Link to home
Start Free TrialLog in
Avatar of tmaususer
tmaususerFlag for United States of America

asked on

Exchange 2010 Power Shell for Quotas

Hello Experts. We are in the process of reducing our users mail boxes from 2 gb to 500 mb. I have the following powershell command
that exports all mailbox names and the total item size for his/her mailbox which then gets export to excel

Get-MailboxStatistics -Database "Mailbox Database xxxxxxx" | Select DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | Export-CSV I:\MBSizes.csv

So it gives me a result like this:

Display Name               TotalItemSize
John Doe                        738.9 MB
Jane Doe                         300.3 MB

What I would like is an additonal command to add on my current one that will give me his/her current prohibit send receive quota as well. So I would want somehting like this that exports to excel

Display Name               TotalItemSize          ProhibitSendReceiveQuota
John Doe                        738.9 MB                 Unlimited
Jane Doe                         300.3 MB                510 MB
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Try the below...
Get-MailboxStatistics -Database "Mailbox Database xxxxxxx" | 
Select DisplayName, ItemCount, TotalItemSize, @{n="TotalSendReceiveQuota";e={(get-mailbox -identity $_).ProhibitSendReceiveQuota}} |
Export-Csv "I:\MBSizes.csv"

Open in new window


That should do it.

Will.
Avatar of tmaususer

ASKER

Will,

The totalSendReceiveQuota column in my excel sheet is blank. Only the header is showing.
Weird... I have just tested this in my lab and it works with no issues. Also you can add -nti to the end of the
Export-Csv "I:\MBSizes.csv" -nti

Open in new window


Will.
I re-ran with the same issue. Here is the result I get.

Display Name               TotalItemSize          ProhibitSendReceiveQuota
John Doe                        738.9 MB                
Jane Doe                         300.3 MB
I have just tested again and for some reason it does not like the -Database parameter. If you run it without the database parameter it works fine.

Get-Mailbox -ResultSize "Unlimited" | Get-MailboxStatistics | 
Select DisplayName, ItemCount, TotalItemSize, @{n="TotalSendReceiveQuota";e={(get-mailbox -identity $_).ProhibitSendReceiveQuota}} |
Export-Csv "I:\MBSizes.csv" -nti

Open in new window


I have gotten around this using the below script...
$Mailboxes = get-mailbox -Datebase "Mailbox Database xxxxxxx" | Select Alias | Export-Csv "c:\mailboxusers.csv" -nti
$Import = import-csv "c:\mailboxusers.csv"
ForEach ($mb in $import) {
Get-MailboxStatistics -Identity $mb |
select DisplayName, TotalItemSize, @{n="ProhibitSendReceiveQuota";e={(get-mailbox -identity $mb).ProhibitSendReceiveQuota}} |
Export-csv "c:\MailboxResults.csv" -nti -append
}

Open in new window


Give that a shot.

Will.
Now I get an eroor a positional parmater cannot be found that acces argument 'Mailbox Database XXXXX'

Category Info:   invalidargument: (:) [Get-Mailbox]. ParameterBindingException
FullyQualifiedErrorID:  PositionParanterNotFound.Get-Mailbox
Ahhhhhhhh!!!!!! LoL. There is a typo. I have corrected the script and it does work now promise (i hope) (just tested).
It should be Get-Mailbox -Database not (Datebase)
Use the updated code below as i have also added some added code.
$Mailboxes = get-mailbox -Database "Mailbox Database xxxxxxx" | Select Alias | Export-Csv "c:\mailboxusers.csv" -nti
$Import = import-csv "c:\mailboxusers.csv"
ForEach ($mb in $import) {
Get-MailboxStatistics -Identity $mb.Alias |
select DisplayName, TotalItemSize, @{n="ProhibitSendReceiveQuota";e={(get-mailbox -identity $mb.Alias).ProhibitSendReceiveQuota}} |
Export-csv "c:\MailboxResults.csv" -nti -append
}

Open in new window


Will.
Ok so the only thing I changed was your import/export paths. Instead of c:\maiboxusers.csv I changed them to I:\mailboxusers.csv. Was this ok to do? the reason I ask it I am still getting an error. (See attached).
Capture.JPG
-Append is a valid switch. Not sure what is happening regarding the script though.

If you type get-help export-csv -full you will see that -Append is a valid switch.

Just ran it in the lab with and without the Export-csv and results were successful both times.

Will.
THis makes no sense as to why it is not working
Do you get the correct results without Export-csv?

Also is the I:\ drive a network drive? Maybe try it locally if that is the case.

Will.
I tried using the export to a local drive and that did not work either. I don't know what to take out regarding the export csv as I am not code expert.
So I don't know why your script did not work but I got this to work.

Get-Mailbox -Database "XXXXXXX" | sort-object TotalItemSize -descending | Select-Object name,PrimarySmtpAddress,@{n="Size(MB)";e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.totalItemsize.value.ToMB()}},@{n="Items"; e = {$MBXstat = Get-MailboxStatistics $_.name ; $MBXstat.itemcount; $MBXstat.storageLimitStatus}},IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,MaxReceiveSize,MaxSendSize | Export-Csv I:\output.csv
ASKER CERTIFIED SOLUTION
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada 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
I see your results but I guess what I am missing is your results are two seperate attachments to where I am looking for only one. The script I posted gives me what I need. I will accept and close on your answer. Thank you very much for pointing me in the right direction. I appreciate it.