I need to get all mailboxes, and witch group there are member of.
You need Quest ActiveRoles Management Shell for this to work:
http://www.quest.com/powershell/activeroles-server.aspx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue $File = "C:\groupslog.txt" $Mailboxes = Get-mailbox -resultsize unlimited | select sAMAccountName,name,alias $Mailboxes | ForEach { $User = Get-QADUser -samaccountname $_.sAMAccountName | Select sAMAccountName, memberOf $Line = $_.sAMAccountName ForEach ($GroupDN In $User.memberOf) { $Group = (Get-QADGroup $GroupDN | Select sAMAccountName).sAMAccountName $Line = "$Line,$Group" } echo $Line } | out-File $File |
In the file c:\groupslog.txt each line is a mailbox, and the first entry is the sAMAccountName, and each entry after this is the group the Mailbox is member of.