retrieve user's mailbox database and display name
Hi all,
Exchange 2007 SP2
Is there a way to retreive every user's mailbox database, display name and windows logon name from exchange powershell?
Thank you.
November 16th, 2010 8:15pm
Hi John
Try this cmdlet:
get-mailbox | select-object database,samaccountname,displayname
/MartinExchange is a passion not just a collaboration software.
Free Windows Admin Tool Kit Click here and download it now
November 16th, 2010 8:45pm
Run
Get-Mailbox -Resultsize Unlimited | ft DisplayName,UserPrincipalName,SamAccountName,DatabaseDJ Grijalva | MCITP: EMA 2007/2010 | www.persistentcerebro.com
November 16th, 2010 8:46pm
It works great. I got DisplayName,UserPrincipalName,SamAccountName,Database
Just wonder can we get these results by each OU? How can I pipe out to the csv file?
Thank you very much.
Free Windows Admin Tool Kit Click here and download it now
November 16th, 2010 9:25pm
You can just add -OrganizationalUnit to the original cmd so:
Get-Mailbox -Resultsize Unlimited -OrganizationalUnit "Sales" | ft DisplayName,UserPrincipalName,SamAccountName,Database
then to export
Get-Mailbox -Resultsize Unlimited -OrganizationalUnit "Sales" | ft DisplayName,UserPrincipalName,SamAccountName,Database | Export-Csv -Path c:\users.csv -NoTypeInformation
If you want to run through each OU then you would have to get a list of the OUs then run a foreach loop on them. Although you could just do this:
Get-Mailbox -Resultsize Unlimited | ft DisplayName,UserPrincipalName,SamAccountName,Database,OrganizationalUnit | Export-Csv -Path c:\users.csv -NoTypeInformation
Then in excel you can sort the users by OU.DJ Grijalva | MCITP: EMA 2007/2010 | www.persistentcerebro.com
November 16th, 2010 9:46pm
If you want a display broken down by OU:
Get-Mailbox -Resultsize Unlimited | group organizationalunit | sort name |% {$_.name;$_.group |ft DisplayName,UserPrincipalName,SamAccountName,Database}[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 16th, 2010 9:52pm
>Get-Mailbox -Resultsize Unlimited -OrganizationalUnit "Sales" | ft DisplayName,UserPrincipalName,SamAccountName,Database
It works great on the screen..
>
>Get-Mailbox -Resultsize Unlimited -OrganizationalUnit "Sales" | ft DisplayName,UserPrincipalName,SamAccountName,Database | Export-Csv -Path c:\users.csv -NoTypeInformation
I got this output in the users.csv file. What am I missing?
_________________
ClassId2e4f51ef21dd47e99d3c952918aff9cd,pageHeaderEntry,pageFooterEntry,autosizeInfo,shapeInfo,groupingEntry
033ecb2bc07a4d43b5ef94ed5a35d280,,,,Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo,
9e210fe47d09416682b841769c78b8a3,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
November 16th, 2010 10:17pm
Hi mjolinor,
It works beautifully. But, how can I pipe out the result to csv file or txt file?
Thank you.
Free Windows Admin Tool Kit Click here and download it now
November 16th, 2010 10:19pm
When you export to csv, use Select instead of ft.
FT adds formatting codes to make it look nice on the screen, but if you try to pipe that straight into export-csv, all those formatting codes go with it, and your csv turns into an ugly mess.
Get-Mailbox -Resultsize Unlimited -OrganizationalUnit "Sales" | select DisplayName,UserPrincipalName,SamAccountName,Database | Export-Csv -Path c:\users.csv -NoTypeInformation
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 16th, 2010 10:25pm
See the other post on how to export to csv. You can't really FT and the export that to .csv, but you can export it to a .txt file like this:
Get-Mailbox -Resultsize Unlimited | group organizationalunit | sort name |% {$_.name;$_.group |ft DisplayName,UserPrincipalName,SamAccountName,Database} | out-string | out-file c:\userlist.txt
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 16th, 2010 10:29pm
it works wonderfully. Thank you.
November 16th, 2010 10:45pm