How do I take the exchange shell command and export it to CSV exchange 2007?
Hello everyone!!I have a command that I use that gives me the output I desire but how can I export it properly to a csv?Get-MailboxStatistics -server “servername” | Sort -Property TotalItemsize | Format-Table DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToKB()};label=”Size(KB)”}, LastLogonTime, LastLogoffTime I have exported it to a csv but it doesn't show any info. The display names are just sids, they don't show the user names and all the other columns are blank.Any help would be appreciated. Thanks in advance
March 12th, 2010 3:12am

Use select-object instead of format-table: Get-MailboxStatistics -server "servername" | Sort -Property TotalItemsize | select-object DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToKB()};label=”Size(KB)”}, LastLogonTime, LastLogoffTime | export-csv c:\report.csv -notype
Free Windows Admin Tool Kit Click here and download it now
March 12th, 2010 3:36am

Just replace format-table with select-object, and then pipe that out to export-csvGet-MailboxStatistics -server “servername” | Sort -Property TotalItemsize | select-object DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToKB()};label=”Size(KB)”}, LastLogonTime, LastLogoffTime | export-csv mbx_stats.csv -notype
March 12th, 2010 3:41am

Thanks for the replies. I had actually tried that beforehand but there was an error. I will try again and I'll post if it doesn't go through
Free Windows Admin Tool Kit Click here and download it now
March 12th, 2010 7:09am

When I use "select-object" the output is an error: Select-Object : Illegal Key LabelAt line:1 char:87select-object <<<< Displayname,Any thoughts?
March 12th, 2010 7:36am

Hi,The below command should helpGet-MailboxStatistics -server “servername” | Sort-Object TotalItemSize -Descending | Select DisplayName, LastLoggedOnUserAccount, ItemCount, LastLogonTime, LastLogoffTime, @{expression={$_.TotalItemSize.value.ToMB()}} | Export-CSV MailboxSizes.csvMahendra
Free Windows Admin Tool Kit Click here and download it now
March 12th, 2010 9:42am

Hi, The below command should help Get-MailboxStatistics -server “servername” | Sort-Object TotalItemSize -Descending | Select DisplayName, LastLoggedOnUserAccount, ItemCount, LastLogonTime, LastLogoffTime, @{expression={$_.TotalItemSize.value.ToMB()}} | Export-CSV MailboxSizes.csv Mahendra select is just an alias for select-object...
March 12th, 2010 10:29am

When I use "select-object" the output is an error: Select-Object : Illegal Key Label At line:1 char:87 select-object <<<< Displayname, Any thoughts? Works OK for me...maybe something is getting messed up in your copy/paste? Try typing it in from scratch.
Free Windows Admin Tool Kit Click here and download it now
March 12th, 2010 10:30am

@Mike --- Yes you are right but the error is due to label=”Size(KB) in the command.Mahendra
March 12th, 2010 11:12am

I get the same error even when just using Select. One more question if anyone knows. I can run this report and get the desired output. Just doesn't work when exporting to CSV. My other question is, from the command I have above, can I include 2 other exchange servers? We have 3 exchange servers in our environment and right now I run this command on a per server level. Is there a way in this command for it to run all 3 for just 1 report? Instead of running it for 1 and then the other
Free Windows Admin Tool Kit Click here and download it now
March 12th, 2010 6:50pm

@Mike --- Yes you are right but the error is due to label=”Size(KB) in the command. Mahendra Yeah, but that is valid on PS v2. Roberto, if your using PS v1 try using "name" instead of "label" in your calculated property: @{name=”Size(KB)”;expression={$_.totalitemsize.value.ToKB()}}
March 12th, 2010 7:02pm

I get the same error even when just using Select. One more question if anyone knows. I can run this report and get the desired output. Just doesn't work when exporting to CSV. My other question is, from the command I have above, can I include 2 other exchange servers? We have 3 exchange servers in our environment and right now I run this command on a per server level. Is there a way in this command for it to run all 3 for just 1 report? Instead of running it for 1 and then the other $result += Get-MailboxServer | Get-MailboxStatistics | Sort -Property TotalItemsize | select-object DisplayName, LastLoggedOnUserAccount, ItemCount, @{name=”Size(KB)”;expression={$_.totalitemsize.value.ToKB()}}, LastLogonTime, LastLogoffTime $result | Export-Csv c:\report.csv -notype
Free Windows Admin Tool Kit Click here and download it now
March 12th, 2010 7:09pm

Thanks for all the replies. Mike you were right at first, it was a copy&paste issue. I had one value in the command that was causing the error. I want to thank you and Mayu whose command does work, it was just my error there.Is there a way to run this command for all 3 exchange servers? or do I have to run the command for one server and then the other?
March 12th, 2010 7:54pm

Thanks for all the replies. Mike you were right at first, it was a copy&paste issue. I had one value in the command that was causing the error. I want to thank you and Mayu whose command does work, it was just my error there. Is there a way to run this command for all 3 exchange servers? or do I have to run the command for one server and then the other? Hi Roberto, To get the info from all 3 servers, try this: $result += Get-MailboxServer | Get-MailboxStatistics | Sort -Property TotalItemsize | select-object DisplayName, LastLoggedOnUserAccount, ItemCount, @{name=”Size(KB)”;expression={$_.totalitemsize.value.ToKB()}}, LastLogonTime, LastLogoffTime $result | Export-Csv c:\report.csv -notype
Free Windows Admin Tool Kit Click here and download it now
March 12th, 2010 9:04pm

That's back to the origial problem of trying to do an export-csv on format-table.$result += Get-MailboxServer | Get-MailboxStatistics | Sort -Property TotalItemsize | select DisplayName, LastLoggedOnUserAccount, ItemCount, @{name=”Size(KB)”;expression={$_.totalitemsize.value.ToKB()}}, LastLogonTime, LastLogoffTime$result | Export-Csv c:\report.csv -notype
March 12th, 2010 9:33pm

That's back to the origial problem of trying to do an export-csv on format-table. $result += Get-MailboxServer | Get-MailboxStatistics | Sort -Property TotalItemsize | select DisplayName, LastLoggedOnUserAccount, ItemCount, @{name=”Size(KB)”;expression={$_.totalitemsize.value.ToKB()}}, LastLogonTime, LastLogoffTime $result | Export-Csv c:\report.csv -notype my bad...copy/paste fail. fixed.
Free Windows Admin Tool Kit Click here and download it now
March 12th, 2010 10:00pm

BTDT :)
March 12th, 2010 10:04pm

Works great. Thanks to everyone for the help!!
Free Windows Admin Tool Kit Click here and download it now
March 12th, 2010 11:05pm

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

Other recent topics Other recent topics