Exploring Hashmaps in Powershell
1 2 3 4 5 6 7 8 9 |
$keep = @{} //declare an empty hashmap /* Next add all the shared mailboxes to the hashmap */ $keep = get-mailbox | ? { $_.recipienttypedetails -eq 'sharedmailbox' } | % { $keep.add($_.name,$_.primarysmtpaddress) } /* Big assumption for this next portion: I'll assume you've put the list of items you want to clean up in a csv with at least a DisplayName and EmailAddress (assuming PrimarySMTP) column */ $cleanup = import-csv /path/to/csv/file.csv $cleanup | % { if (-not $keep.containskey($_.displayname)) { remove-mailbox -identity $_.displayname } } |
1 2 3 4 5 6 7 |
$myList = New-Object Collections.Generic.List[string] $myList.Add("one") $myList.Add("two") $myList.Add("three") $myHash = @{ } $myHash.Add("list", $myList) |