I am setting up a report to email myself mailbox stats but part of it is blank. Someone else tested it for themselves on their exchange server and it worked fine. so what is wrong with mine?<\/p>\n
DisplayName : User Name<\/p>\n
Database : mailboxdb01<\/p>\n
TotalItemSize : <\/p>\n
ItemCount : <\/p>\n
IssueWarningQuota : unlimited<\/p>\n
ProhibitSendQuota : unlimited<\/p>\n
But the last six results do have the information that I am wanting.<\/p>\n
My command<\/p>\n
. 'E:\\Exchange Binaries\\Bin\\RemoteExchange.ps1'\nConnect-ExchangeServer –auto\nGet-Mailbox | Select-Object Displayname, Database,\n @{Name='TotalItemSize'; Expression={[String]::join(\";\", (Get-MailboxStatistics -identity $_.identity).TotalItemSize)}},\n @{Name='ItemCount'; Expression={[String]::join(\";\",(Get-MailboxStatistics -identity $_.identity).ItemCount)}},\n IssueWarningQuota, ProhibitSendQuota |\n set-variable Result\nSend-MailMessage -SmtpServer outlook -From noreply@ -To ronw@ -Subject 'Mail Stats Report' -BodyAsHTML -Body (($Result | convertTo-HTML) -join \"`n\")\n<\/code><\/pre>","upvoteCount":5,"answerCount":9,"datePublished":"2014-10-22T13:37:27.000Z","author":{"@type":"Person","name":"ron7582_1","url":"https://community.spiceworks.com/u/ron7582_1"},"acceptedAnswer":{"@type":"Answer","text":"What I don’t like about that approach is calling Get-MailboxStatistics twice. Nothing really wrong with it but it is slow, and you’ve already gotten the data once so why do it twice? Here’s my approach that just does it once:<\/p>\n
ForEach ($MB in (Get-Mailbox))\n{ $MB | Get-MailboxStatistics | Select @{Name=\"DisplayName\";Expression={$MB.DisplayName}},@{Name=\"Database\";Expression={$MB.Database}},TotalItemSize,ItemCount,@{Name=\"IssueWarningQuota\";Expression={$MB.IssueWarningQuota}},@{Name=\"ProhibitSendQuota\";Expression={$MB.ProhibitSendQuota}}\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2014-10-22T14:29:04.000Z","url":"https://community.spiceworks.com/t/powershell-to-get-mailboxstatistics/350291/5","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}},"suggestedAnswer":[{"@type":"Answer","text":"I am setting up a report to email myself mailbox stats but part of it is blank. Someone else tested it for themselves on their exchange server and it worked fine. so what is wrong with mine?<\/p>\n
DisplayName : User Name<\/p>\n
Database : mailboxdb01<\/p>\n
TotalItemSize : <\/p>\n
ItemCount : <\/p>\n
IssueWarningQuota : unlimited<\/p>\n
ProhibitSendQuota : unlimited<\/p>\n
But the last six results do have the information that I am wanting.<\/p>\n
My command<\/p>\n
. 'E:\\Exchange Binaries\\Bin\\RemoteExchange.ps1'\nConnect-ExchangeServer –auto\nGet-Mailbox | Select-Object Displayname, Database,\n @{Name='TotalItemSize'; Expression={[String]::join(\";\", (Get-MailboxStatistics -identity $_.identity).TotalItemSize)}},\n @{Name='ItemCount'; Expression={[String]::join(\";\",(Get-MailboxStatistics -identity $_.identity).ItemCount)}},\n IssueWarningQuota, ProhibitSendQuota |\n set-variable Result\nSend-MailMessage -SmtpServer outlook -From noreply@ -To ronw@ -Subject 'Mail Stats Report' -BodyAsHTML -Body (($Result | convertTo-HTML) -join \"`n\")\n<\/code><\/pre>","upvoteCount":5,"datePublished":"2014-10-22T13:37:27.000Z","url":"https://community.spiceworks.com/t/powershell-to-get-mailboxstatistics/350291/1","author":{"@type":"Person","name":"ron7582_1","url":"https://community.spiceworks.com/u/ron7582_1"}},{"@type":"Answer","text":"Get-MailboxStatistics has issues when operating on a pipeline with multiple objects. I don’t know why. Here is a work around:<\/p>\n
$mailboxes = Get-Mailbox \n$Result = ForEach ($mailbox in $mailboxes) { \n $mailbox | Select-Object Displayname, Database,\n @{Name='TotalItemSize'; Expression={[String]::join(\";\", (Get-MailboxStatistics -identity $_.identity).TotalItemSize)}},\n @{Name='ItemCount'; Expression={[String]::join(\";\",(Get-MailboxStatistics -identity $_.identity).ItemCount)}},\n IssueWarningQuota, ProhibitSendQuota \n}\nSend-MailMessage -SmtpServer outlook -From noreply@ -To ronw@ -Subject 'Mail Stats Report' -BodyAsHTML -Body (($Result | convertTo-HTML) -join \"`n\")\n<\/code><\/pre>\nHere you are only sending single object down the pipe to Get-MailboxStatistics. And each iteration of the loop allows Get-MailboxStatistics to complete before moving on to the next one.<\/p>","upvoteCount":0,"datePublished":"2014-10-22T14:09:54.000Z","url":"https://community.spiceworks.com/t/powershell-to-get-mailboxstatistics/350291/2","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"
Got the email but it is totally blank. No text at all<\/p>","upvoteCount":0,"datePublished":"2014-10-22T14:17:58.000Z","url":"https://community.spiceworks.com/t/powershell-to-get-mailboxstatistics/350291/3","author":{"@type":"Person","name":"ron7582_1","url":"https://community.spiceworks.com/u/ron7582_1"}},{"@type":"Answer","text":"
Sorry, I put $Result as $Results. Change the typo and try again.<\/p>","upvoteCount":0,"datePublished":"2014-10-22T14:19:13.000Z","url":"https://community.spiceworks.com/t/powershell-to-get-mailboxstatistics/350291/4","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"
EDIT: Whoops, left the | Select -First 5 in there by accident, which I used for testing. Took that out!<\/p>","upvoteCount":0,"datePublished":"2014-10-22T14:47:00.000Z","url":"https://community.spiceworks.com/t/powershell-to-get-mailboxstatistics/350291/6","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}},{"@type":"Answer","text":"
lol yea the first 5 was throwing me off. Is it possible to sort-object itemsinfolder ?<\/p>","upvoteCount":0,"datePublished":"2014-10-22T14:52:26.000Z","url":"https://community.spiceworks.com/t/powershell-to-get-mailboxstatistics/350291/7","author":{"@type":"Person","name":"ron7582_1","url":"https://community.spiceworks.com/u/ron7582_1"}},{"@type":"Answer","text":"
Add:<\/p>\n
$Result = $Result | Sort-Object ItemCount\n<\/code><\/pre>\nbetween the loop and send-mailmessage<\/p>","upvoteCount":1,"datePublished":"2014-10-22T14:54:40.000Z","url":"https://community.spiceworks.com/t/powershell-to-get-mailboxstatistics/350291/8","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"
My final result, worked perfect thanks everyone<\/p>\n
(($Result | sort-object TotalItemSize -descending | convertTo-HTML) -join \"`n\")\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2014-10-22T15:17:30.000Z","url":"https://community.spiceworks.com/t/powershell-to-get-mailboxstatistics/350291/9","author":{"@type":"Person","name":"ron7582_1","url":"https://community.spiceworks.com/u/ron7582_1"}}]}}