Jorge Ocampo
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
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
ASKER
the above wont give me total mailbox size and what percentage till it reaches it quota
Hello ,
Please try the below logic,
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
}
ASKER
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
ASKER
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"
ASKER
[PS] C:\Users\adm\Desktop>.\Mai lboxQuota. ps1
Unrecognized token in source text.
At C:\Users\adm\Desktop\Mailb oxQuota.ps 1:6 char:21
+ $properties = <<<< @ { alias = $mx.alias
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnrecognizedToken
Unrecognized token in source text.
At C:\Users\adm\Desktop\Mailb
+ $properties = <<<< @ { alias = $mx.alias
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnrecognizedToken
ASKER
hi dinesh i am getting the above error message any help would be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Or you can set different location
$Report |Sort-Object QuotaPercent -Descending |Export-CSV c:\temp\QUOTA.csv
Or you can set different location
ASKER
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\Mailb oxSizeQuot a.ps1:51 char:71
+ [int64]$usr_mailboxstats_t otaldelete ditemsize = [convert]::ToInt64 <<<< (((($usr_mailboxstats.Tota lDeletedIt emSize.ToS tring().sp lit("(")[- 1]).split( ")")[0]).s plit(" ")[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\Mailb oxSizeQuot a.ps1:60 char:47
+ [INT64]$usr_quota = [convert]::ToInt64 <<<< (((($usr_mailbox.ProhibitS endQuota.T oString(). split("(") [-1]).spli t(")")[0]) .split(" ")[0]-replace '[,]',''))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Attempted to divide by zero.
At C:\Users\adm\desktop\Mailb oxSizeQuot a.ps1:63 char:112
+ $usr_quota_percentage = [INT]((($usr_mailboxstats_ totalitems ize + $usr_mailboxstats_totaldel eteditemsi ze) / <<<< $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\Mailb oxSizeQuot a.ps1:49 char:64
+ [int64]$usr_mailboxstats_t otalitemsi ze = [convert]::ToInt64 <<<< (((($usr_mailboxstats.Tota lItemSize. ToString() .split("(" )[-1]).spl it(")")[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\Mailb oxSizeQuot a.ps1:51 char:71
+ [int64]$usr_mailboxstats_t otaldelete ditemsize = [convert]::ToInt64 <<<< (((($usr_mailboxstats.Tota lDeletedIt emSize.ToS tring().sp lit("(")[- 1]).split( ")")[0]).s plit(" ")[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\Mailb oxSizeQuot a.ps1:60 char:47
+ [INT64]$usr_quota = [convert]::ToInt64 <<<< (((($usr_mailbox.ProhibitS endQuota.T oString(). split("(") [-1]).spli t(")")[0]) .split(" ")[0]-replace '[,]',''))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Attempted to divide by zero.
At C:\Users\adm\desktop\Mailb oxSizeQuot a.ps1:63 char:112
+ $usr_quota_percentage = [INT]((($usr_mailboxstats_ totalitems ize + $usr_mailboxstats_totaldel eteditemsi ze) / <<<< $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\Mailb oxSizeQuot a.ps1:49 char:64
+ [int64]$usr_mailboxstats_t otalitemsi ze = [convert]::ToInt64 <<<< (((($usr_mailboxstats.Tota lItemSize. ToString() .split("(" )[-1]).spl it(")")[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\Mailb oxSizeQuot a.ps1:51 char:71
+ [int64]$usr_mailboxstats_t otaldelete ditemsize = [convert]::ToInt64 <<<< (((($usr_mailboxstats.Tota lDeletedIt emSize.ToS tring().sp lit("(")[- 1]).split( ")")[0]).s plit(" ")[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\Mailb oxSizeQuot a.ps1:60 char:47
+ [INT64]$usr_quota = [convert]::ToInt64 <<<< (((($usr_mailbox.ProhibitS endQuota.T oString(). split("(") [-1]).spli t(")")[0]) .split(" ")[0]-replace '[,]',''))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Attempted to divide by zero.
At C:\Users\adm\desktop\Mailb oxSizeQuot a.ps1:63 char:112
+ $usr_quota_percentage = [INT]((($usr_mailboxstats_ totalitems ize + $usr_mailboxstats_totaldel eteditemsi ze) / <<<< $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\Mailb
+ [int64]$usr_mailboxstats_t
+ 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\Mailb
+ [INT64]$usr_quota = [convert]::ToInt64 <<<< (((($usr_mailbox.ProhibitS
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Attempted to divide by zero.
At C:\Users\adm\desktop\Mailb
+ $usr_quota_percentage = [INT]((($usr_mailboxstats_
+ 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\Mailb
+ [int64]$usr_mailboxstats_t
+ 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\Mailb
+ [int64]$usr_mailboxstats_t
+ 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\Mailb
+ [INT64]$usr_quota = [convert]::ToInt64 <<<< (((($usr_mailbox.ProhibitS
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Attempted to divide by zero.
At C:\Users\adm\desktop\Mailb
+ $usr_quota_percentage = [INT]((($usr_mailboxstats_
+ 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\Mailb
+ [int64]$usr_mailboxstats_t
+ 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\Mailb
+ [int64]$usr_mailboxstats_t
+ 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\Mailb
+ [INT64]$usr_quota = [convert]::ToInt64 <<<< (((($usr_mailbox.ProhibitS
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Attempted to divide by zero.
At C:\Users\adm\desktop\Mailb
+ $usr_quota_percentage = [INT]((($usr_mailboxstats_
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
Script is working because I've tested.
#TYPE System.Management.Automati on.PSCusto mObject
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
#TYPE System.Management.Automati
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
ASKER
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
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.
Here is the link to the reference script Tom provided you...
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
Here is the link to the reference script Tom provided you...
ASKER
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,
Thanks
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
Thanks
ASKER
@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.
It worked for me, could you please past your code here.
Last line should be out of braces.
ASKER
$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.prohibitsendreceivequo ta
#calc = (Totalsize *100)/Currentsize
#Res = 100 - (calc)
}
$obj += new-object -typename psobject -property $properties
}
$obj | select-object primarysmtpaddress,Display name,Curre ntsize,Tot alsize | Export-csv "C:\temp\ee.csv" -notypeinformation
$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.prohibitsendreceivequo
#calc = (Totalsize *100)/Currentsize
#Res = 100 - (calc)
}
$obj += new-object -typename psobject -property $properties
}
$obj | select-object primarysmtpaddress,Display
Please paste your output too
ASKER
CVS ERRORS
"primarysmtpaddress","Disp layname"," Currentsiz e","Totals ize"
,"ZZ_Admin ","493210B","unlimited"
,"ADMIKN","1015040049B","1 086MB"
__________________________ _____WINDO W 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.IndexOutOfRangeExce ption,Micr osoft.Exch ange.Manag ement.Mapi Tasks.GetM ailboxStat istics
"primarysmtpaddress","Disp
,"ZZ_Admin ","493210B","unlimited"
,"ADMIKN","1015040049B","1
__________________________
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.
+ $mxs = Get-MailboxStatistics <<<< -Identity $user
+ CategoryInfo : NotSpecified: (:) [Get-MailboxStatistics], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeExce
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 ?
If Yes it should be like
C:\Users\adm\desktop\Mailb oxSizeQuot a.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
are you using entry parameter for quota ?
C:\Users\adm\desktop\MailboxSizeQuot a.ps1:51
If Yes it should be like
C:\Users\adm\desktop\Mailb
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
ASKER
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\Mailb oxSizeQuot a.ps1:63 char:5
+ $usr_quota_percentage = [INT]((($usr_mailboxstats_ totalitems ize +
$usr_mailb ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~
~~~
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
Attempted to divide by zero.
At C:\Users\adm\Desktop\Mailb
+ $usr_quota_percentage = [INT]((($usr_mailboxstats_
$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
It looks like you have mailbox with 0 emails so script can't divide by 0
ASKER
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_ totalitems ize + $usr_mailboxstats_totaldel eteditemsi ze) / $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.P rohibitSen dQuota.ToS tring().sp lit("(")[- 1]).split( ")")[0]).s plit(" ")[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_ totalitems ize + $usr_mailboxstats_totaldel eteditemsi ze) /1000)*100)
$usr_quota_percentage = [INT]((($usr_mailboxstats_
It looks like in your network one or more mailbox usr_quota = 0 after conversion to Integer
[INT64]$usr_quota = [convert]::ToInt64(((($usr
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_
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Best solution provided. No more other questions from author
Open in new window