Here is the output from get-mailboxpermission (its a test user)
PS C:\Windows\system32> Get-MailboxPermission –Identity
"[email protected]<mailto:[email protected]>" | Select-Object
-Property User, AccessRights
User
AccessRights
----
------------
NT AUTHORITY\SELF
{FullAccess, ReadPermission}
NAMPRD05\Administrator
{FullAccess}
NAMPRD05\Domain Admins
{FullAccess}
NAMPRD05\Enterprise Admins
{FullAccess}
NAMPRD05\Organization Management
{FullAccess}
NT AUTHORITY\SYSTEM
{FullAccess}
NT AUTHORITY\NETWORK SERVICE
{ReadPermission}
PRDMGT01\View-Only Organization Management
{ReadPermission}
NAMPRD05\Administrator
{FullAccess, DeleteItem,
ReadPermission, ChangePermission, ChangeOwner}
NAMPRD05\Domain Admins
{FullAccess, DeleteItem,
ReadPermission, ChangePermission, ChangeOwner}
NAMPRD05\Enterprise Admins
{FullAccess, DeleteItem,
ReadPermission, ChangePermission, ChangeOwner}
NAMPRD05\Organization Management
{FullAccess, DeleteItem,
ReadPermission, ChangePermission, ChangeOwner}
NAMPRD05\Public Folder Management
{ReadPermission}
NAMPRD05\Exchange Servers
{FullAccess, ReadPermission}
NAMPRD05\Exchange Trusted Subsystem
{FullAccess, DeleteItem,
ReadPermission, ChangePermission, ChangeOwner}
NAMPRD05\Managed Availability Servers
{ReadPermission}
I need to have the mailbox added to the output, since I am building a report to
generate a list of permissions to be removed from multiple mailboxes.
Ideas on best method?
Sent from Windows Mail
From: Mike Mitchell<mailto:[email protected]>
Sent: Wednesday, April 15, 2015 10:47 AM
To: [email protected]<mailto:[email protected]>
I love this data structure!
I use it like this:
$hashtable = @{} # – this creates the table.. do it once
$hashtable[$key] = $value # – this populates the table.. do it once for each
unique key.
Then I iterate it like this:
Foreach ($key in $hashtable.keys) { <blah blah > }
So the question is: what are you wanting to use for the key (unique) and what
will be the value the unique key points to?
So, $hashtable[$user.emailaddress] = $perm lets you associate one permission
entry with a user’s unique email address. The problem here is each
user.emailaddress will probably have multiple permission entries. I would be
inclined to have the hashtable[key] point to an array list of permission
entries.
I’m sure there are other ways to slice this up.
Confession: Hash tables (dictionaries) are my favorite data structure; Array
Lists are my second favorite.
Hth. Mike
From: [email protected] [mailto:[email protected]] On
Behalf Of [email protected]
Sent: Wednesday, April 15, 2015 7:00 AM
To: [email protected]
Subject: [powershell] HashTable Help.
I really need to get my head around working with hashtables better.
Here is my snippet that I’m having problems with:
#Get list of mailboxes to work with.
$UserList = import-csv -Path "c:\temp\o365_termed_users.csv"
#Create Empty hashtable
$hashtable = $null
$hashtable = @{}
#Iterate through the list of user mailboxes
ForEach ($user in $userlist)
{
#Get the mailbox permissions, strip off the ones i dont care about.
$mailboxpermissions = Get-MailboxPermission –Identity $user.emailaddress |
where-object {$_.User -notlike "*PRD*"} | where-object {$_.User -notlike "NT
Auth*"} | Select-Object -Property User, AccessRights
#Make sure we have permissions to work with.
IF ($mailboxpermissions -ne $null)
{
#Iterate through the permissions, and add them to the hashtable.
ForEach ($perm in $mailboxpermissions)
{$hashtable.add($user.emailaddress,$perm.user,$perm.accessrights)}
}
}
I’m having two issues.
1. Adding the $user.emailaddress blows up with the overload error, I need to
add it from the prior ForEach loop, so i know what mailbox has what permission.
1. I’m not sure if my IF statement is setup properly, some of the mailboxes
will return no permissions, and I know trying to add a null value to a
hashtable won’t work correctly.
Sent from Windows Mail
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1