0

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.

kaiguy
  • 3
  • 1
  • 3

2 Answers2

1

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
JBaldridge
  • 484
  • 3
  • 10
  • Unfortunately, it's only returning a blank csv when I try to run this script. I think there's something wrong with my Exchange Powershell, but I'm not sure what. – kaiguy Aug 29 '16 at 19:09
  • When you start powershell what context are you running under? Are you a normal user or are you an Exchange admin? Also note that if you run as admin that might elevate your account that you are logged into the machine with, but that doesn't mean that user has the rights it needs to run commands against your Exchange server. Start the Exchange Management Shell (EMS) as a user that has rights. Then run `Get-Mailbox -ResultSize 10` and see if it returns anything. It should give you something. If it doesn't then you're having problems with EMS it sounds like. – JBaldridge Aug 29 '16 at 19:21
  • Yeah, it looks like there was an issue with Exchange admin roles. Thanks for your help. – kaiguy Aug 29 '16 at 19:37
0

A simple way to do it is to pipe in all your databases to the query:

get-MailboxDatabase | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label=”TotalItemSize(MB)”;expression={$_.TotalItemSize.Value.ToMB()}},ItemCount -auto
smwk
  • 570
  • 2
  • 5
  • 14
  • I get the follow error when I try to run your script: get-MailboxDatabase : The term 'get-MailboxDatabase' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + get-MailboxDatabase | Get-MailboxStatistics | Sort-Object TotalItemSize -Descend ... + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (get-MailboxDatabase:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException – kaiguy Aug 29 '16 at 17:57