Powershell – Exchange 2013 Powershell script for getting list of mailbox sizes error

exchange-2013powershell

EDIT: It looks like the issue was a problem with Exchange admin roles. When my supervisor upgraded our server to Exchange 2013, it looks like my account wasn't added to the any of them. That also explains why I was never able to log onto the EAC with my account. I've updated the admin roles and my previous scripts are now working.

When I use the script below, it is only returning information for myself.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize

I've also tried the following two scripts, but both return with errors that the -Server or -Database parameters cannot be found.

Get-MailboxStatistics -Server SERVERNAME | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label=”TotalItemSize(MB)”;expression={$_.TotalItemSize.Value.ToMB()}},ItemCount -auto

Get-MailboxStatistics -database "DATABASENAME" | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label=”TotalItemSize(MB)”;expression={$_.TotalItemSize.Value.ToMB()}},ItemCount -auto

I've tried running Exchange Management Powershell as administrator, as well as using "#Enable Exchange cmdlets" first, but neither seem to help the issue.

Let me know if any other information is needed, and thanks in advance.

Best Answer

Please note the very last line if you are not seeing on the screen what you think you should be seeing. I can't remember if I wrote this myself or adapted it (years ago) from something I found online. Works in Exchange 2010 as well (if you change to V14). If you open the Exchange powershell window you can omit the part that connects to Exchange. I've also left my testing line in there.

# Make powershell connection to Exchange
. 'E:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'


$AllMailboxes = @()
$Mailboxes = Get-Mailbox -ResultSize Unlimited | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, RetainDeletedItemsFor, Alias
#$Mailboxes = Get-Mailbox -ResultSize 10 | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, RetainDeletedItemsFor, Alias
foreach ($Mailbox in $Mailboxes){
    $MailboxStats = "" |Select  DisplayName,Database,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,TotalItemSizeInMB,ItemCount,StorageLimitStatus,RetainDeletedItemsFor
    $Stats = Get-MailboxStatistics -Identity $Mailbox.Alias
    $MailboxStats.DisplayName = $Mailbox.DisplayName 
    $MailboxStats.Database = $Mailbox.Database
    if ($Mailbox.IssueWarningQuota -eq "unlimited") {$MailboxStats.IssueWarningQuota = "database default"}
    else {$MailboxStats.IssueWarningQuota = $Mailbox.IssueWarningQuota}
    if ($Mailbox.ProhibitSendQuota -eq "unlimited") {$MailboxStats.ProhibitSendQuota = "database default"}
    else {$MailboxStats.ProhibitSendQuota = $Mailbox.ProhibitSendQuota}
    if ($Mailbox.ProhibitSendReceiveQuota -eq "unlimited") {$MailboxStats.ProhibitSendReceiveQuota = "database default"}
    else {$MailboxStats.ProhibitSendReceiveQuota = $Mailbox.ProhibitSendReceiveQuota}
    if ($Stats.TotalItemSize -eq $NULL){$MailboxStats.TotalItemSizeInMB = 0}
    else {$MailboxStats.TotalItemSizeInMB = $Stats.TotalItemSize.Value.ToMB()}
    $MailboxStats.ItemCount = $Stats.ItemCount
    $MailboxStats.StorageLimitStatus = $Stats.StorageLimitStatus
    $MailboxStats.RetainDeletedItemsFor = $Mailbox.RetainDeletedItemsFor
    $AllMailboxes += $MailboxStats
}
$AllMailboxes | Sort-Object StorageLimitStatus,TotalItemSizeInMB -descending | Export-Csv E:\Temp\mailboxsizes.csv -NoTypeInformation
Related Topic