How do i Export Mailbox Stats to a CSV
Hi i am using the following Code: Get-Mailbox -ResultSize Unlimited -SortBy Displayname | ForEach-Object { $mbx = $_ | Select DisplayName, Alias, RecipientTypeDetails $Inboxstats = Get-MailboxFolderStatistics $_ -FolderScope Inbox | Where {$_.foldertype -eq "Inbox"} | Select ItemsInFolder, FolderSize $Calstats = Get-MailboxFolderStatistics $_ -FolderScope Calendar | Where {$_.foldertype -eq "Calendar"} | Select ItemsInFolder, FolderSize Get-MailboxStatistics $_ | ForEach { $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Item Count" -Value $_.ItemCount $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Size (MB)" -Value $InboxStats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Item Count" -Value $Inboxstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "Calendar Total Size (MB)" -value $Calstats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Calendar Total Item Count" -value $Calstats.ItemsInFolder } $mbx } | export-csv -notypeinformation c:\test3.txt This works perfect! however i need to also pull off stats for Sent Items, Deleted Items and a another folder called Iris Mail Law, i have tried to add these folders on however it keep up errors, Any help would be appreciated as i am racking my brains here. Thank You.
October 5th, 2012 7:58am

What have you tried, and what errors did you get? I've not tried it yet, but I'd have thought that $_.foldertype -eq "SentItems" $_.foldertype -eq "DeletedItems" and $_.displayname -eq "Mail Law" would work. Mobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2012 9:20am

I amended the code just to add on sent items: Get-Mailbox -ResultSize Unlimited -SortBy Displayname | ForEach-Object { $mbx = $_ | Select DisplayName, Alias, RecipientTypeDetails $Inboxstats = Get-MailboxFolderStatistics $_ -FolderScope Inbox | Where {$_.foldertype -eq "Inbox"} | Select ItemsInFolder, FolderSize $Calstats = Get-MailboxFolderStatistics $_ -FolderScope Calendar | Where {$_.foldertype -eq "Calendar"} | Select ItemsInFolder, FolderSize $SentItemstats = Get-MailboxFolderStatistics $_ -FolderScope Sent Items | Where {$_.foldertype -eq "SentItems"} | Select ItemsInFolder, FolderSize Get-MailboxStatistics $_ | ForEach { $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Item Count" -Value $_.ItemCount $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Size (MB)" -Value $InboxStats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Item Count" -Value $Inboxstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "Calendar Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Calendar MAIL Total Item Count" -Value $_.ItemCount $mbx | Add-Member -MemberType NoteProperty -Name "Sent Items Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Sent Items Total Item Count" -Value $_.ItemCount } $mbx } | export-csv -notypeinformation c:\mailboxdetails.txt But received the following error Get-MailboxFolderStatistics : Cannot bind parameter 'FolderScope'. Cannot conve rt value "Sent" to type "Microsoft.Exchange.Data.Directory.SystemConfiguration. ElcFolderType" due to invalid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are "Calendar , Contacts, DeletedItems, Drafts, Inbox, JunkEmail, Journal, Notes, Outbox, Sen tItems, Tasks, All, ManagedCustomFolder, RssSubscriptions, SyncIssues, Conversa tionHistory". At line:6 char:70 + $SentItemstats = Get-MailboxFolderStatistics $_ -FolderScope <<<< S ent Items | Where {$_.foldertype -eq "SentItems"} | Select ItemsInFolder, Folde rSize
October 5th, 2012 9:49am

The error message is saying that your -FolderScope values need to be in this list: http://msdn.microsoft.com/en-us/library/microsoft.exchange.data.directory.systemconfiguration.elcfoldertype(v=exchg.140).aspx so, I would try -FolderScope SentItems instead.Mobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2012 9:58am

I realised there was a space between sent items, i changed that, the code currently looks like this Get-Mailbox -ResultSize Unlimited -SortBy Displayname | ForEach-Object { $mbx = $_ | Select DisplayName, Alias, RecipientTypeDetails $Inboxstats = Get-MailboxFolderStatistics $_ -FolderScope Inbox | Where {$_.foldertype -eq "Inbox"} | Select ItemsInFolder, FolderSize $Calstats = Get-MailboxFolderStatistics $_ -FolderScope Calendar | Where {$_.foldertype -eq "Calendar"} | Select ItemsInFolder, FolderSize $SentItemstats = Get-MailboxFolderStatistics $_ -FolderScope SentItems | Where {$_.foldertype -eq "SentItems"} | Select ItemsInFolder, FolderSize Get-MailboxStatistics $_ | ForEach { $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Item Count" -Value $_.ItemCount $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Size (MB)" -Value $InboxStats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Item Count" -Value $Inboxstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "Calendar Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Calendar MAIL Total Item Count" -Value $_.ItemCount $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Item Count" -Value $_.ItemCount } $mbx } | export-csv -notypeinformation c:\mailboxdetails.txt It exported to the csv file however the data in the sent items column is the same as the calendars columns for all users, so the sent items must of pulled the calendars data instead :S really confused.
October 5th, 2012 9:59am

I think it's a copy/paste error. Can you see where the Inbox stats get added to $mbx: $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Size (MB)" -Value $InboxStats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Item Count" -Value $Inboxstats.ItemsInFolder try to duplicate this where the Calendar and SentItems stats get added by using $CalStats.FolderSize.ToMB() $CalStats.ItemsInFolder (and the same for $SentItemsStats) instead of the $_.TotalItemSize.Value.ToMB() $_.ItemCount values.Mobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2012 10:08am

Right here: "Calendar Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Calendar MAIL Total Item Count" -Value $_.ItemCount $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Item Count" -Value $_.ItemCount You are picking up the results of Get-MailboxStatistics ($_), not the variables that contain the folder statistics you created in the first loop.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
October 5th, 2012 10:13am

You appear to be missing the Get-Mailbox to feed it the mailbox identities.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2012 10:54am

Amended the code as suggested: Get-Mailbox -ResultSize Unlimited -SortBy Displayname | ForEach-Object { $mbx = $_ | Select DisplayName, Alias, RecipientTypeDetails $Inboxstats = Get-MailboxFolderStatistics $_ -FolderScope Inbox | Where {$_.foldertype -eq "Inbox"} | Select ItemsInFolder, FolderSize $Calstats = Get-MailboxFolderStatistics $_ -FolderScope Calendar | Where {$_.foldertype -eq "Calendar"} | Select ItemsInFolder, FolderSize $SentItemsstats = Get-MailboxFolderStatistics $_ -FolderScope SentItems | Where {$_.foldertype -eq "SentItems"} | Select ItemsInFolder, FolderSize Get-MailboxStatistics $_ | ForEach { $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Item Count" -Value $_.ItemCount $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Size (MB)" -Value $InboxStats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Item Count" -Value $Inboxstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "Calendar Total Size (MB)" -value $Calstats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Calendar Total Item Count" -value $Calstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Size (MB)" -Value $SentItemsstats.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Item Count" -Value $SentItemsstats.ItemCount } $mbx } | export-csv -notypeinformation c:\mailboxdetails.txt Error i have now is as follows: You cannot call a method on a null-valued expression. At line:14 char:140 + $mbx | Add-Member -MemberType NoteProperty -Name "SentItems To tal Size (MB)" -Value $SentItemsstats.TotalItemSize.Value.ToMB( <<<< ) You cannot call a method on a null-valued expression. At line:14 char:140 + $mbx | Add-Member -MemberType NoteProperty -Name "SentItems To tal Size (MB)" -Value $SentItemsstats.TotalItemSize.Value.ToMB( <<<< ) You cannot call a method on a null-valued expression. At line:14 char:140 + $mbx | Add-Member -MemberType NoteProperty -Name "SentItems To tal Size (MB)" -Value $SentItemsstats.TotalItemSize.Value.ToMB( <<<< ) You cannot call a method on a null-valued expression. At line:14 char:140
October 5th, 2012 11:00am

I've seen that error before when using implicit remoting, rather than an actual EMS shell.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2012 11:08am

In this line $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Size (MB)" -Value $SentItemsstats.TotalItemSize.Value.ToMB() try using $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Size (MB)" -Value $SentItemsstats.FolderSize.ToMB() which seems to work for the other folders.Mobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
October 5th, 2012 11:18am

I got it to work Thank you for all your help dudes, this comes down to user error me been the user! i blame because its friday. Heres the code i used: Get-Mailbox -ResultSize Unlimited -SortBy Displayname | ForEach-Object { $mbx = $_ | Select DisplayName, Alias, RecipientTypeDetails $Inboxstats = Get-MailboxFolderStatistics $_ -FolderScope Inbox | Where {$_.foldertype -eq "Inbox"} | Select ItemsInFolder, FolderSize $Calstats = Get-MailboxFolderStatistics $_ -FolderScope Calendar | Where {$_.foldertype -eq "Calendar"} | Select ItemsInFolder, FolderSize $SentItemsstats = Get-MailboxFolderStatistics $_ -FolderScope SentItems | Where {$_.foldertype -eq "SentItems"} | Select ItemsInFolder, FolderSize $DeletedItemsstats = Get-MailboxFolderStatistics $_ -FolderScope DeletedItems | Where {$_.foldertype -eq "DeletedItems"} | Select ItemsInFolder, FolderSize Get-MailboxStatistics $_ | ForEach { $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Item Count" -Value $_.ItemCount $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Size (MB)" -Value $InboxStats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Item Count" -Value $Inboxstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "Calendar Total Size (MB)" -value $Calstats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Calendar Total Item Count" -value $Calstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Size (MB)" -value $SentItemsstats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Item Count" -value $SentItemsstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "DeletedItems Total Size (MB)" -value $DeletedItemsstats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "DeletedItems Total Item Count" -value $DeletedItemsstats.ItemsInFolder } $mbx } | export-csv -notypeinformation c:\FullReport.txt AS Lee Derbyshire Pointed Out copy and paste error, however i have a custom folder now that is not in the list of Folder Scopes, what would i put for coding.
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2012 11:20am

Depending on your environment, that totalitemsize may be returned as a string, rather than a bytequantified type. This is a loss of object fidelity caused by the object serialization / deserialization that takes place in remoting process. You may need to parse the byte count out of that and do the unit conversion yourself. [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
October 5th, 2012 11:24am

I have to admit that I'm not sure what you'd use for a custom folder. Not having a PS console in front of me now, I'd guess something like $CustomFolderStats = Get-MailboxFolderStatistics $_ -FolderScope All | Where {$_.displayname -eq "Mail Law"} | Select ItemsInFolder, FolderSizeMobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2012 11:29am

hmmm No Luck from that i recieve You cannot call a method on a null-valued expression. At line:20 char:129 + $mbx | Add-Member -MemberType NoteProperty -Name "IRIS Total S ize (MB)" -value $CustomFolderstats.FolderSize.ToMB( <<<< ) You cannot call a method on a null-valued expression. At line:20 char:129 + $mbx | Add-Member -MemberType NoteProperty -Name "IRIS Total S ize (MB)" -value $CustomFolderstats.FolderSize.ToMB( <<<< ) You cannot call a method on a null-valued expression. At line:20 char:129 + $mbx | Add-Member -MemberType NoteProperty -Name "IRIS Total S ize (MB)" -value $CustomFolderstats.FolderSize.ToMB( <<<< )
October 5th, 2012 11:41am

Okay, I'll try to find something that works here, and get back to you.Mobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2012 12:52pm

$CustomFolderStats = Get-MailboxFolderStatistics $_ -FolderScope All | Where {$_.displayname -eq "Mail Law"} | Select ItemsInFolder, FolderSize Not displayname, but name. They don't have a displayname property..... $CustomFolderStats = Get-MailboxFolderStatistics $_ -FolderScope All | Where {$_.name -eq "Mail Law"} | Select ItemsInFolder, FolderSize [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
October 5th, 2012 1:01pm

Try this: $CustomFolderStats = Get-MailboxFolderStatistics | Where {$_.folderpath -eq "/Mail Law"} | Select ItemsInFolder, FolderSize The -FolderScope is used to tell the cmd to start its search in a particular place. E.g. If your "/Mail Law" folder is under the Inbox, use -FolderScope "Inbox" to speed things up a little bit (and $_.folderpath="/Inbox/Mail Law". If it's at root level, you can use "All", or probably ignore it. Mobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2012 1:12pm

You beat me to it :) I'm too used to seeing "displayname" in other schemas.Mobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
October 5th, 2012 1:17pm

It does seem an odd departure from normal naming conventions.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2012 1:19pm

You might need to put some error trapping in with that. If you use an absolute path, it's going to throw errors if the user moves that folder. If you set the Scope to All and search by name, you could get back multiple results if they've created another folder with the same name at a different location....[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
October 5th, 2012 1:26pm

Hi Jammy, Any updates? If your question is answered it would be nice if you mark it accordingly. Thanks,Fiona Liao TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
October 26th, 2012 8:03am

Still no luck for the custom folder: i recieve this error now You cannot call a method on a null-valued expression. At line:20 char:138 + $mbx | Add-Member -MemberType NoteProperty -Name "Iris Law Mai l Total Size (MB)" -value $CustomFolderStats.FolderSize.ToMB( <<<< ) You cannot call a method on a null-valued expression. That error was generated from using this code: $CustomFolderStats = Get-MailboxFolderStatistics $_ -FolderScope All | Where {$_.name -eq "Iris Law Mail"} | Select ItemsInFolder, FolderSize
October 26th, 2012 8:33am

What is displayed if you just type this into a PS console. Supply your own mailbox name, assuming you have the particular folder in your mailbox: Get-MailboxFolderStatistics YourMailboxName -FolderScope All | Where {$_.name -eq "Iris Law Mail"} | Select ItemsInFolder, FolderSize Mobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
Free Windows Admin Tool Kit Click here and download it now
October 26th, 2012 9:27am

It displays the items in the folder and the folder size :S i dont know where im going wrong then
October 26th, 2012 10:49am

Can you see anything wrong with the code below.. Get-Mailbox -ResultSize Unlimited -SortBy Displayname | ForEach-Object { $mbx = $_ | Select DisplayName, Alias, RecipientTypeDetails $Inboxstats = Get-MailboxFolderStatistics $_ -FolderScope Inbox | Where {$_.foldertype -eq "Inbox"} | Select ItemsInFolder, FolderSize $Calstats = Get-MailboxFolderStatistics $_ -FolderScope Calendar | Where {$_.foldertype -eq "Calendar"} | Select ItemsInFolder, FolderSize $SentItemsstats = Get-MailboxFolderStatistics $_ -FolderScope SentItems | Where {$_.foldertype -eq "SentItems"} | Select ItemsInFolder, FolderSize $DeletedItemsstats = Get-MailboxFolderStatistics $_ -FolderScope DeletedItems | Where {$_.foldertype -eq "DeletedItems"} | Select ItemsInFolder, FolderSize $CustomFolderStats = Get-MailboxFolderStatistics $_ -FolderScope All | Where {$_.name -eq "Iris Law Mail"} | Select ItemsInFolder, FolderSize Get-MailboxStatistics $_ | ForEach { $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Size (MB)" -Value $_.TotalItemSize.Value.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Mailbox Total Item Count" -Value $_.ItemCount $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Size (MB)" -Value $InboxStats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Inbox Total Item Count" -Value $Inboxstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "Calendar Total Size (MB)" -value $Calstats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Calendar Total Item Count" -value $Calstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Size (MB)" -value $SentItemsstats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "SentItems Total Item Count" -value $SentItemsstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "DeletedItems Total Size (MB)" -value $DeletedItemsstats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "DeletedItems Total Item Count" -value $DeletedItemsstats.ItemsInFolder $mbx | Add-Member -MemberType NoteProperty -Name "Iris Law Mail Total Size (MB)" -value $CustomFolderStats.FolderSize.ToMB() $mbx | Add-Member -MemberType NoteProperty -Name "Iris Law Mail Total Item Count" -value $CustomFolderStats.ItemsInFolder } $mbx } | export-csv -notypeinformation c:\FullReport5.txt
Free Windows Admin Tool Kit Click here and download it now
October 26th, 2012 10:50am

If that works for your mailbox, then I think the code works okay as long as you have the Iris Law Mail folder in your mailbox, but fails if it encounters a mailbox that doesn't have the folder. You could try putting some of the code in a try ... catch thing (or just a try thing): try { $mbx | Add-Member -MemberType NoteProperty -Name "IRIS Total Size (MB)" -value $CustomFolderstats.FolderSize.ToMB() }Mobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
October 26th, 2012 11:12am

Looks okay, but you won't know until the other problem's fixed.Mobile OWA For Smartphone www.leederbyshire.com email a@t leederbyshire d.0.t c.0.m
Free Windows Admin Tool Kit Click here and download it now
October 26th, 2012 11:15am

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

Other recent topics Other recent topics