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
tmaususerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
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.
tmaususerAuthor Commented:
Will,

The totalSendReceiveQuota column in my excel sheet is blank. Only the header is showing.
Will SzymkowskiSenior Solution ArchitectCommented:
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.
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

tmaususerAuthor Commented:
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
Will SzymkowskiSenior Solution ArchitectCommented:
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.
tmaususerAuthor Commented:
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
Will SzymkowskiSenior Solution ArchitectCommented:
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.
tmaususerAuthor Commented:
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
Will SzymkowskiSenior Solution ArchitectCommented:
-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.
tmaususerAuthor Commented:
THis makes no sense as to why it is not working
Will SzymkowskiSenior Solution ArchitectCommented:
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.
tmaususerAuthor Commented:
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.
tmaususerAuthor Commented:
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
Will SzymkowskiSenior Solution ArchitectCommented:
I have illustrated exactly what i have done in my lab. Make sure that you are not missing any steps...
Exact script code i am using in my lab
$Mailboxes = get-mailbox -Database "Mailbox Database 1946240478" | Select Alias | Export-Csv "c:\move\mailboxusers.csv" -nti
$Import = import-csv "c:\move\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:\move\mailboxResults.csv" -nti -append
}

Open in new window

This is me running the script from Exchange Management Console
powershell112.JPG
This is the directory where the files were created
powershell113.JPG
I have also attached the files so that you can see that in the Mailbox Results CSV it does export all of the correct data.

A side from that i do not know what is different about your PS session and why it does not like -Append switch.

Will.
MailboxResults.csv
mailboxusers.csv

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tmaususerAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.