Get-MailboxFolderStatistics Exporting FolderandSubfolderSize does not deliver data
I am trying to run a powershell script to basically send an email with Mailbox Folder Size Statistics to support staff. The main part of the script I'm running is: $body = get-mailboxfolderstatistics -identity $UserMailbox | select Name,ItemsInFolder,@{label="Folder & Subfolder Size MB";expression = {$_.folderandsubfoldersize.ToMB()}} | ConvertTo-HTML -head $a -body "<H2><font color=white>$UserMailbox Mailbox Size</font color></H2>" There's a little more to the script than this.. but my question is when I run the command from a prompt without doing any export... just the: get-mailboxfolderstatistics -identity $UserMailbox | select Name,ItemsInFolder,@{label="Folder & Subfolder Size MB";expression = {$_.folderandsubfoldersize.ToMB()}} I get the results I'm looking for, 3 columns name,itemsinfolder,folderandsubfoldersize .. all with the appropriate data. When I try to export it out and send via email.. the folderandsubfoldersize is missing data. No results are returned. Any idea why in the shell it works.. but in the export it fails? Thanks!
January 16th, 2012 11:04am

You might want to assign the properties to variables and then export the variables.Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
January 16th, 2012 5:38pm

Hello, If you export $body to one html file, can you see the data for folderandsubfoldersize? $body = get-mailboxfolderstatistics -identity $UserMailbox | select Name,ItemsInFolder,@{label="Folder & Subfolder Size MB";expression = {$_.folderandsubfoldersize.ToMB()}} | ConvertTo-HTML -head $a -body "<H2><font color=white>$UserMailbox Mailbox Size</font color></H2>"| Out-File c:\test.html If you can see the data in the html file, this may not issue with the command you post, you can check the commands you used to send the email. In my lab, I use these commands to test for the issue, and I can see the data in the message: $a= "<style>BODY{background-color:peachpuff;}</style>" $body = get-mailboxfolderstatistics -identity $UserMailbox | select Name,ItemsInFolder,@{label="Folder & Subfolder Size MB";expression = {$_.folderandsubfoldersize.ToMB()}} | ConvertTo-HTML -head $a -body "<H2><font color=white>$UserMailbox Mailbox Size</font color></H2>" New-MailMessage -Subject "Mailbox Information" -Body $body -Mailbox Administrator -BodyFormat Html Then I can see one email (included the information) Under Administrator’s Draft folder. Thanks, Evan Liu TechNet Subscriber Support in forum If you have any feedback on our support, please contact tngfb@microsoft.com Evan Liu TechNet Community Support
January 17th, 2012 1:52am

Hi, Please use the below Powershell script which will give you the desired output in email. Code ------------------------------------------------------------------------------------------------------------------------------------------------- #Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin ################## # Mail variables # ################## $enablemail="yes" $smtpServer = "SMTP server" $mailfrom = "from address" $mailto = "to address" $mailcc = "cc address" $date = get-date ############# # Variables # ############# $filelocation="C:\Reports\ExchangeMailboxStat{0:yyyyMMdd-HHmm}.htm" -f (Get-Date) Get-Date | Select-Object DateTime | convertTo-HTML -head $a -Title "Exchange System HealthCheck" | Out-File $filelocation $a = $a + "<style>" $a = $a + "BODY{background-color:#717d7d;}" #$a = $a + "BODY{background-color:#11E9F5;}" $a = $a + "TABLE.sortable thead {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}" $a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#827b60}" $a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#c9c299}" $a = $a + "</style>" $MailboxUser = Get-Mailbox -Resultsize Unlimited -Server SHL-TOL-XVS01 | Where {($_.RecipientType -eq "UserMailbox") -and ($_.HiddenFromAddressListsEnabled -eq $False)} $MessageBody = $MailboxUser | Get-MailboxStatistics | Sort-Object -Descending TotalItemSize |Select DisplayName, ItemCount, @{Expression={$_.TotalItemSize.Value.ToMB()};Name="MailboxSize MB"}, @{label="TotalDeletedItemSize (MB)";expression={$_.TotalDeletedItemSize.Value.ToMB()} }, DatabaseName | ConvertTo-html -body "<Font Color = Black><B>-----------------------Exchange Mailboxes Status -----------------</B></Font Color>" | Out-File $filelocation -append ###################### # E-mail HTML output # ###################### if ($enablemail -match "yes") { $msg = new-object Net.Mail.MailMessage $att = new-object Net.Mail.Attachment($filelocation) $smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.From = $mailfrom $msg.To.Add($mailto) $msg.Cc.Add($mailcc) $msg.Subject = "Exchange Mailbox Statistics Report" $msg.Body = "Hi All, Please find the Exchange Mailbox Statistics Report for weekly review." $msg.Attachments.Add($att) $msg.Attachments.Add($file) $smtp.Send($msg) } Shashi
Free Windows Admin Tool Kit Click here and download it now
January 17th, 2012 5:05am

Hello, If you export $body to one html file, can you see the data for folderandsubfoldersize? $body = get-mailboxfolderstatistics -identity $UserMailbox | select Name,ItemsInFolder,@{label="Folder & Subfolder Size MB";expression = {$_.folderandsubfoldersize.ToMB()}} | ConvertTo-HTML -head $a -body "<H2><font color=white>$UserMailbox Mailbox Size</font color></H2>"| Out-File c:\test.html If you can see the data in the html file, this may not issue with the command you post, you can check the commands you used to send the email. In my lab, I use these commands to test for the issue, and I can see the data in the message: $a= "<style>BODY{background-color:peachpuff;}</style>" $body = get-mailboxfolderstatistics -identity $UserMailbox | select Name,ItemsInFolder,@{label="Folder & Subfolder Size MB";expression = {$_.folderandsubfoldersize.ToMB()}} | ConvertTo-HTML -head $a -body "<H2><font color=white>$UserMailbox Mailbox Size</font color></H2>" New-MailMessage -Subject "Mailbox Information" -Body $body -Mailbox Administrator -BodyFormat Html Then I can see one email (included the information) Under Administrator’s Draft folder. Thanks, Evan Liu TechNet Subscriber Support in forum If you have any feedback on our support, please contact tngfb@microsoft.com Evan Liu TechNet Community Support
January 17th, 2012 9:45am

Hi, Any updates on this issue? Thanks, Evan Liu TechNet Subscriber Support in forum If you have any feedback on our support, please contact tngfb@microsoft.com Evan Liu TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
January 18th, 2012 4:01am

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

Other recent topics Other recent topics