This isn’t going to work this way. A hashtable consists of an unordered (normally) list of Keys and Values. A given Key can only have one Value. In your code below, you are attempting to give a single Key multiple Values.
Now, that Value can be an object, so it can be a container for many pieces of data. What is the desired result? From: [email protected] [mailto:[email protected]] On Behalf Of [email protected] Sent: Wednesday, April 15, 2015 10: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
