Formatting Output of Powershell Commands - Get-Mailbox
Get-Mailbox | format-table alias, emailaddresses -auto > C:\get-mailbox.csv Hi All, When typing the above command in EMS and outputing to csv it works, BUT - when I open the csv in Excel, alias and email address is in one cell on excel - so basically have to cut / paste it into a different cell and this is a long list. any ideas / suggestions to format the output which can be just a case of sizing the cells in Excel ? Kind Regards
November 26th, 2010 6:25am

If you're wanting a csv, use select-object and export-csv instead of format-table: Get-Mailbox | select-object alias, emailaddresses | export-csv C:\get-mailbox.csv[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 26th, 2010 6:36am

If you're wanting a csv, use select-object and export-csv instead of format-table: Get-Mailbox | select-object alias, emailaddresses | export-csv C:\get-mailbox.csv [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " " Thanks Mjolinor, Just tried your command, it did separated them in separate colums but the output is like this : "Administrator","Microsoft.Exchange.Data.ProxyAddressCollection" so "Administrator" is a separate column and "Microsoftexchangedataproxyaddresscollection" is a separate column, where it should had email address, alias any suggestions ?
November 26th, 2010 6:46am

Try this: Get-Mailbox | select-object alias, @{label = "emailaddresses";expression = {[string]$_.emailaddresses}} | export-csv C:\get-mailbox.csv[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 26th, 2010 7:06am

Hi Mjolinor Thanks for the prompt responses - it worked. Why it won't use the format-wide option ? any thoughts ? also, How can I check what other properties related to mailboxes I can export to csv via get-mailbox command ? Thanks again for your support !
November 26th, 2010 7:15am

The format- commands are for formatting for screen output. It adds formatting codes that make the output look nice on the screen, but doesn't comma-separate them. If you pipe that output directly to a file it's not comma separated (so you end up with everything in one column). If you pipe it to export-csv the formatting codes go with it and your csv comes out ugly. You can export any of the properties of the object to csv by including them in the Select-object list. Easiest way to see what they are is get-mailbox <username> | format-list Some of them are arrays (like emailaddresses) that may require some additional code to get them to come out like you want. If you omit the select-object and just pipe the get-mailbox output directly to export-csv, you'll get them all.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 26th, 2010 7:27am

Hi Mjolinor, Thanks for the clarification, I am going to get a Powershell Book soon :-) but have never touched programming or its concepts so get stucked every now and then :-) Also, if one wants to document an existing exchange server (apart from List of MBX DB and PF DB): a) List of Mailboxes b) List of Public Folders c) List of Mail Enabled Public Folders d) List of Mail Contacts e) List of Transport Rules I will try to get the mailcontacts the same way you posted the get-mailbox command above so that should be ok, BUT : For Transport rules, is there a way I can export them in a way that they have the description or action of what they were doing ? like for e.g. if I have a mailcontact being redirected to another mailbox via transport rule, is there a way we can export that detail, so if we are re-building or something we know which mail-contacts do what ? anyother point you may want to give in documenting the Exchange Box ? Thanks so much ! Kind Regards
November 26th, 2010 7:45am

Check the documentation on the following cmdlets: get-mailbox get-publicfolder get-mailbpublicfolder get-mailcontact As far as the transport rule goes there is a Description field you may want to look at, and each one has a Commets field that contains user-supplied text that you may want to update for documentation. I don't think I've ever seen it stated explicitly, but IMHO, for purposes of documentation and reporting, use export-csv. For purposes of backup and recovery, use export-clixml. Again, that's my opinion, and someone with more experience / knowlege may have better advice.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 26th, 2010 9:04am

Hi Mjolinor, Thanks so much for your answers and explanation ! Really Grateful, I am going to document all commands from my threads and create a blog / wiki off it - will post a link here when it happens ! Regards
November 26th, 2010 9:26am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics