tmaususer
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
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
ASKER
Will,
The totalSendReceiveQuota column in my excel sheet is blank. Only the header is showing.
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
Will.
Export-Csv "I:\MBSizes.csv" -nti
Will.
ASKER
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
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.
I have gotten around this using the below script...
Give that a shot.
Will.
Get-Mailbox -ResultSize "Unlimited" | Get-MailboxStatistics |
Select DisplayName, ItemCount, TotalItemSize, @{n="TotalSendReceiveQuota";e={(get-mailbox -identity $_).ProhibitSendReceiveQuota}} |
Export-Csv "I:\MBSizes.csv" -nti
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
}
Give that a shot.
Will.
ASKER
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.G et-Mailbox
Category Info: invalidargument: (:) [Get-Mailbox]. ParameterBindingException
FullyQualifiedErrorID: PositionParanterNotFound.G
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.
Will.
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
}
Will.
ASKER
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
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.
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.
ASKER
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.
Also is the I:\ drive a network drive? Maybe try it locally if that is the case.
Will.
ASKER
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.
ASKER
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.val ue.ToMB()} },@{n="Ite ms"; e = {$MBXstat = Get-MailboxStatistics $_.name ; $MBXstat.itemcount; $MBXstat.storageLimitStatu s}},IssueW arningQuot a,Prohibit SendQuota, ProhibitSe ndReceiveQ uota,MaxRe ceiveSize, MaxSendSiz e | Export-Csv I:\output.csv
Get-Mailbox -Database "XXXXXXX" | sort-object TotalItemSize -descending | Select-Object name,PrimarySmtpAddress,@{
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Open in new window
That should do it.
Will.