Link to home
Start Free TrialLog in
Avatar of Jorge Ocampo
Jorge OcampoFlag for United States of America

asked on

Exchange Mailbox Report Total Size and Quota Reach Percentage

Hi,

I am trying to get all an exchange mailbox report for all mailboxes and their quota set configuration and what percentage left to reach quota.

any help is appreciated

Regards,
J
Avatar of Tom Cieslik
Tom Cieslik
Flag of United States of America image

Replace SERVER with your email server name

get-mailbox -server "server" -ResultSize unlimited | Where {$_.UseDatabaseQuotaDefaults -eq $false} | Sort-Object DisplayName | ft DisplayName,IssueWarningQuota,ProhibitSendQuota > C:\quota_exceptions.txt

Open in new window

Avatar of Jorge Ocampo

ASKER

the above wont give me total mailbox size and what percentage till it reaches it quota
Hello ,

Please try the below logic,

$users = get-mailbox -recipientypedetails "usermailbox" -resultsize unlimited
Foreach ($user in $user)
{
      $mx = Get-Mailbox -Identity $user
      $mxs = Get-MailboxStatistics -Identity $user
      $properties = @ { alias = $mx.alias
                                      currentsize =  $mxs.totalitemsize
                                      Totalsize = $mx.prohibitsendreceivequota
                                     }
      $obj = New-Object -typename psobject -property $properties
  Write-output $obj
}

Open in new window

could i use above to query all mailboxes?
Yes, it will for all user mailboxes, if you want to query all mailboxes , then remove -recipientypedetails "usermailbox" on first line
i try to do a | export-csv but it fail any help with that would be appreciated
try this,

$users = get-mailbox -recipientypedetails "usermailbox" -resultsize unlimited
Foreach ($user in $user)
{
      $mx = Get-Mailbox -Identity $user
      $mxs = Get-MailboxStatistics -Identity $user
      $properties = @ { alias = $mx.alias
                                      currentsize =  $mxs.totalitemsize
                                      Totalsize = $mx.prohibitsendreceivequota
                                     }
      $obj = New-Object -typename psobject -property $properties
}
$obj | select-object alias,currentsize,totalsize | export-csv "filename.csv"

Open in new window

[PS] C:\Users\adm\Desktop>.\MailboxQuota.ps1
Unrecognized token in source text.
At C:\Users\adm\Desktop\MailboxQuota.ps1:6 char:21
+       $properties =  <<<< @ { alias = $mx.alias
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnrecognizedToken
hi dinesh i am getting the above error message any help would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Tom Cieslik
Tom Cieslik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
awesome exactly what i needed i try to export-csv and it gives me an error any help with that would be appreciated.
Yes,, just replace last line with

$Report |Sort-Object QuotaPercent -Descending |Export-CSV c:\temp\QUOTA.csv

Open in new window


Or you can set different location
Error all over any advise would be appreciated

Exception calling "ToInt64" with "1" argument(s): "Input string was not in a correct format."
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:51 char:71
+     [int64]$usr_mailboxstats_totaldeleteditemsize = [convert]::ToInt64 <<<< (((($usr_mailboxstats.TotalDeletedItemSize.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]','')
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "ToInt64" with "1" argument(s): "Input string was not in a correct format."
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:60 char:47
+         [INT64]$usr_quota = [convert]::ToInt64 <<<< (((($usr_mailbox.ProhibitSendQuota.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]',''))
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Attempted to divide by zero.
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:63 char:112
+     $usr_quota_percentage = [INT]((($usr_mailboxstats_totalitemsize + $usr_mailboxstats_totaldeleteditemsize) / <<<<  $usr_quota)*100)
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

Exception calling "ToInt64" with "1" argument(s): "Input string was not in a correct format."
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:49 char:64
+     [int64]$usr_mailboxstats_totalitemsize = [convert]::ToInt64 <<<< (((($usr_mailboxstats.TotalItemSize.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]',''))
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "ToInt64" with "1" argument(s): "Input string was not in a correct format."
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:51 char:71
+     [int64]$usr_mailboxstats_totaldeleteditemsize = [convert]::ToInt64 <<<< (((($usr_mailboxstats.TotalDeletedItemSize.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]','')
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "ToInt64" with "1" argument(s): "Input string was not in a correct format."
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:60 char:47
+         [INT64]$usr_quota = [convert]::ToInt64 <<<< (((($usr_mailbox.ProhibitSendQuota.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]',''))
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Attempted to divide by zero.
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:63 char:112
+     $usr_quota_percentage = [INT]((($usr_mailboxstats_totalitemsize + $usr_mailboxstats_totaldeleteditemsize) / <<<<  $usr_quota)*100)
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

Exception calling "ToInt64" with "1" argument(s): "Input string was not in a correct format."
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:49 char:64
+     [int64]$usr_mailboxstats_totalitemsize = [convert]::ToInt64 <<<< (((($usr_mailboxstats.TotalItemSize.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]',''))
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "ToInt64" with "1" argument(s): "Input string was not in a correct format."
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:51 char:71
+     [int64]$usr_mailboxstats_totaldeleteditemsize = [convert]::ToInt64 <<<< (((($usr_mailboxstats.TotalDeletedItemSize.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]','')
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "ToInt64" with "1" argument(s): "Input string was not in a correct format."
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:60 char:47
+         [INT64]$usr_quota = [convert]::ToInt64 <<<< (((($usr_mailbox.ProhibitSendQuota.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]',''))
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Attempted to divide by zero.
At C:\Users\adm\desktop\MailboxSizeQuota.ps1:63 char:112
+     $usr_quota_percentage = [INT]((($usr_mailboxstats_totalitemsize + $usr_mailboxstats_totaldeleteditemsize) / <<<<  $usr_quota)*100)
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException
Script is working because I've tested.

#TYPE System.Management.Automation.PSCustomObject                        
DisplayName      TotalItemSize      TotalDeletedItemSize      ProhibitSendQuota      QuotaPercent
Yarek Ostaniewicz      21391447449      4078347      10737418240      199
Henry Zyborowicz      9122279993      612592      10737418240      85
Anna Kasperska      8622971671      46421635      10737418240      81
Voytek Kaniewski      9413027487      684775      11811160064      80
Carol O'Connor      8297964369      1162302      10737418240      77
Lukasz Kaniewski      7844703997      1833290      10737418240      73
Agnieszka Burkiewicz      5600296574      7322530      8589934592      65
Heather Maher      13048108982      593273      21474836480      61
Jacek Wasielak      6440912019      125600      10737418240      60
Pawel Kaniewski      4277592304      379555      10737418240      40
Lindsay Gotthold      3812889067      488374      10737418240      36
Tom Cieslik      3521166152      501751      10737418240      33
Agnieszka Zerdecka      3528278995      0      10737418240      33
Jeff Petro      3312792180      0      10737418240      31
Adam Tulik      3341756482      311921      10737418240      31
Dorothy Lukasz      3186659394      371892      10737418240      30
the below allows me to get what i needed just need to convert it to look at all mailboxes instead of one

# Get-MailboxQuota.ps1
# Script for showing mailbox size and quota
 
# Exit the script if username is not found
If ($args[0] -eq $null) {
      Write-Host "Error: No user specified" -ForegroundColor "Red"
      break
}
 
# Get the username from the command line argument
$username = $args[0]
 
# Get the mailbox, break if it's not found
$mb = Get-Mailbox $username -ErrorAction Stop
 
# Get the mailbox statistics
$mbstats = Get-MailboxStatistics $username
 
# If the mailbox is using the database quotas then read them, otherwise read them from the mailbox
If ($mb.UseDatabaseQuotaDefaults -eq $true) {
      $quota = (Get-MailboxDatabase -Identity $mb.Database).ProhibitSendQuota.Value.ToMB()
} else {
      $quota = $mb.ProhibitSendQuota.Value.ToMB()
}
 
# Get the mailbox size and convert it from bytes to megabytes
$size = $mbstats.TotalItemSize.Value.ToMB()
 
# Write the output
Write-Host "Mailbox:   " $mb.DisplayName
Write-Host "Size (MB): " $size
Write-Host "Quota (MB):" $quota
Write-Host "Percent:   " ($size/$quota*100)
Write-Host

Open in new window

My guess is that you will get those errors on mailboxes that have a quota set to unlimited (default).  This would include user, room, equipment and shared mailboxes.

You don't need to edit line 34.  Just run the command like what is below to get all mailboxes that have used 30% or more of their defined quota.  Because my lab is so small, I checked for those larger than 0.01 percent.

TGet-MailboxSizeQuota.ps1 30

Open in new window


Here is the link to the reference script Tom provided you...

no go same error messages
The errors can be disregarded. Did you review the output in the report?
awesome exactly what i needed i try to export-csv and it gives me an error any help with that would be appreciated.
You just said that before so I assume You've tested script and was working for you.

Than You've asked how to send report to CSV file so I've told you how.
I've tested all and It is working.

If is not working for you maybe you just put some modification to script that it not supposed to be there.

Try copy script again.

@Todd.
I have few users with Unlimited quota set and script still working, so this is not a issue.
Hi,

Apologize for the dealy,
please try below script,

$obj =@()
$users = get-mailbox -resultsize unlimited
Foreach ($user in $users)
{
	$mx = Get-Mailbox -Identity $user
	$mxs = Get-MailboxStatistics -Identity $user
	$properties = @{Displayname = $mx.displayname
			  Currentsize = $mxs.totalitemsize 
			  Totalsize = $mx.prohibitsendreceivequota
			  #calc = (Totalsize *100)/Currentsize
			  #Res = 100 - (calc)
			}
	$obj += new-object -typename psobject -property $properties
	
} 
$obj | select-object Displayname,Currentsize,Totalsize | Export-csv "C:\ee.csv" -notypeinformation

Open in new window


Thanks
@dinesh the export doesnt work it overwrites the same line in the export over and over :(
Hi,
It worked for me, could you please past your code here.
Last line should be out of braces.
$obj =@()
$users = get-mailbox -resultsize unlimited
Foreach ($user in $users)
{
      $mx = Get-Mailbox -Identity $user
      $mxs = Get-MailboxStatistics -Identity $user
      $properties = @{Displayname = $mx.displayname
                    Currentsize = $mxs.totalitemsize
                    Totalsize = $mx.prohibitsendreceivequota
                    #calc = (Totalsize *100)/Currentsize
                    #Res = 100 - (calc)
                  }
      $obj += new-object -typename psobject -property $properties
      
}
$obj | select-object primarysmtpaddress,Displayname,Currentsize,Totalsize | Export-csv "C:\temp\ee.csv" -notypeinformation
Please paste your output too
CVS ERRORS

"primarysmtpaddress","Displayname","Currentsize","Totalsize"
,"ZZ_Admin ","493210B","unlimited"
,"ADMIKN","1015040049B","1086MB"

_______________________________WINDOW ERRORS___________________________
validation errors have been encountered:
WARNING: Object cannot be saved because its ExchangeVersion property is 0.20 (15.0.0.0), which is not supported by the current version 0.1 (8.0.535.0). You will need a later version of Exchange.
WARNING: The value of property 'RecipientTypeDetails', 549755813888, is not defined in the Enum type 'RecipientTypeDetails'.
WARNING: An unexpected error has occurred and a Watson dump is being generated: Index was outside the bounds of the array.
Get-MailboxStatistics : Index was outside the bounds of the array.
At C:\Users\admin\Desktop\M4.ps1:6 char:30
+     $mxs = Get-MailboxStatistics <<<<  -Identity $user
    + CategoryInfo          : NotSpecified: (:) [Get-MailboxStatistics], IndexOutOfRangeException
    + FullyQualifiedErrorId : System.IndexOutOfRangeException,Microsoft.Exchange.Management.MapiTasks.GetMailboxStatistics
I'm not sure why script I've provided is not working for you. For me is perfectly fine

are you using entry parameter for quota ?

C:\Users\adm\desktop\MailboxSizeQuota.ps1:51

If Yes it should be like

C:\Users\adm\desktop\MailboxSizeQuota.ps1 51   (space between ps1 and number)

Or you can modify line 34, put number 1 and run script without parameters

GO to Powerschell
cd\
cd Users\adm\desktop

.\MailboxSizeQuota.ps1

ENTER
i change line 34 to 1 and the below error continues without an output csv


Attempted to divide by zero.
At C:\Users\adm\Desktop\MailboxSizeQuota.ps1:63 char:5
+     $usr_quota_percentage = [INT]((($usr_mailboxstats_totalitemsize +
$usr_mailb ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException
So there is not any list mailboxes you get and any suggestion which mailbox is causing problem ?
It looks like you have mailbox with 0 emails so script can't divide by 0
i assume that is correct the export is zero bytes :( and keeps looping the same error message
There is a math in script:

$usr_quota_percentage = [INT]((($usr_mailboxstats_totalitemsize + $usr_mailboxstats_totaldeleteditemsize) / $usr_quota)*100)
It looks like in your network one or more mailbox usr_quota = 0 after conversion to Integer

[INT64]$usr_quota = [convert]::ToInt64(((($usr_mailbox.ProhibitSendQuota.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]',''))

In that case it will be error since you can't / 0

You can try replace line 63  / $usr_quota by some numner, let say 1000

$usr_quota_percentage = [INT]((($usr_mailboxstats_totalitemsize + $usr_mailboxstats_totaldeleteditemsize) /1000)*100)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Best solution provided. No more other questions from author