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.
2.
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