Carl Billington
asked on
Apply mailbox quotas based on current mailbox size (Powershell)?
RE: Exchange 2010
I have recently joined a company that have completely unrestructed mailbox quotas and I'm trying to decide the most appropriate way of introducting / enforcing mailbox quotas for the organisation.
Therefore I would like to generate a powershell script that will assign specific mailbox quotas based on the size of the individuals mailbox.
For example;
If a user has a mailbox size between 1 > 2 GB I would like the script to apply the following quota; -IssueWarningQuota 950MB -ProhibitSendQuota 2048MB -ProhibitSendReceiveQuota 2048MB
If a user has a mailbox size between 2 > 3 GB I would like the script to apply the following quota; -IssueWarningQuota 1024MB -ProhibitSendQuota 3072MB -ProhibitSendReceiveQuota 3072MB
If a user has a mailbox size between 3 > 4 GB I would like the script to apply the following quota; -IssueWarningQuota 2048MB -ProhibitSendQuota 4096MB -ProhibitSendReceiveQuota 4096MB
Can you help with this powershell script? I would also like to assign exclusions if possible?
I have recently joined a company that have completely unrestructed mailbox quotas and I'm trying to decide the most appropriate way of introducting / enforcing mailbox quotas for the organisation.
Therefore I would like to generate a powershell script that will assign specific mailbox quotas based on the size of the individuals mailbox.
For example;
If a user has a mailbox size between 1 > 2 GB I would like the script to apply the following quota; -IssueWarningQuota 950MB -ProhibitSendQuota 2048MB -ProhibitSendReceiveQuota 2048MB
If a user has a mailbox size between 2 > 3 GB I would like the script to apply the following quota; -IssueWarningQuota 1024MB -ProhibitSendQuota 3072MB -ProhibitSendReceiveQuota 3072MB
If a user has a mailbox size between 3 > 4 GB I would like the script to apply the following quota; -IssueWarningQuota 2048MB -ProhibitSendQuota 4096MB -ProhibitSendReceiveQuota 4096MB
Can you help with this powershell script? I would also like to assign exclusions if possible?
ASKER
Wow, I'm going to test this shortly. How do I assign exclusions? Say for example I wanted to exclude; carl, anna, robert
Ok. In that case add one more condition like
if(($Mailbox.Displayname -like *carl*) -or ($Mailbox.Displayname -like *anna*) -or ($Mailbox.DisplayName -like *robert*)){Set-Mailbox $Mailbox.DisplayName -IssueWarningQuota unlimited -ProhibitSendQuota unlimited -ProhibitSendReceiveQuota unlimited -UseDatabaseRetentionDefau lts $false }
Or if you are looking to exclude those mailboxes from changing the limits then you can add the below condition to first command.
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like *cart*) -or ($_.Displayname -like *anna*) -or ($_.Displayname -like *robert*)}
So, this will omit this mailboxes from the initial list itself. If you have the exact display name then you can modify the condition as $_.DisplayName -eq 'DisplayName
if(($Mailbox.Displayname -like *carl*) -or ($Mailbox.Displayname -like *anna*) -or ($Mailbox.DisplayName -like *robert*)){Set-Mailbox $Mailbox.DisplayName -IssueWarningQuota unlimited -ProhibitSendQuota unlimited -ProhibitSendReceiveQuota unlimited -UseDatabaseRetentionDefau
Or if you are looking to exclude those mailboxes from changing the limits then you can add the below condition to first command.
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like *cart*) -or ($_.Displayname -like *anna*) -or ($_.Displayname -like *robert*)}
So, this will omit this mailboxes from the initial list itself. If you have the exact display name then you can modify the condition as $_.DisplayName -eq 'DisplayName
ASKER
So to confirm this is the command below? (this will run the command for all mailboxes excluding anna, robert and carl)
Let me know?
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like *cart*) -or ($_.Displayname -like *anna*) -or ($_.Displayname -like *robert*)}
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics
foreach($Mailbox in $AllMailboxes){
$SizeMB = $Mailbox.TotalItemSize.Val ue.ToMB()
if(($SizeMB -lt 2048) -or ($SizeMB -gt 1024)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefau lts $false -IssueWarningQuota 950MB -ProhibitSendQuota 2048MB -ProhibitSendReceiveQuota 2048MB}
if(($SizeMB -lt 3072) -or ($SizeMB -gt 2048)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefau lts $false -IssueWarningQuota 1024MB -ProhibitSendQuota 3072MB -ProhibitSendReceiveQuota 3072MB}
if(($SizeMB -lt 4096) -or ($SizeMB -gt 3072)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefau lts $false -IssueWarningQuota 2048MB -ProhibitSendQuota 4096MB -ProhibitSendReceiveQuota 4096MB}
}
Let me know?
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like *cart*) -or ($_.Displayname -like *anna*) -or ($_.Displayname -like *robert*)}
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics
foreach($Mailbox in $AllMailboxes){
$SizeMB = $Mailbox.TotalItemSize.Val
if(($SizeMB -lt 2048) -or ($SizeMB -gt 1024)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefau
if(($SizeMB -lt 3072) -or ($SizeMB -gt 2048)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefau
if(($SizeMB -lt 4096) -or ($SizeMB -gt 3072)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefau
}
Exactly. You got me right.
ASKER
I get this error?
You must provide a value expression on the right-hand side of the '-like' operator.
At C:\powershell.ps1:1 char:104
+ AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like <<<< *cart*)
-or ($_.Displayname -like *anna*) -or ($_.Displayname -like *robert*)}
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : ExpectedValueExpression
[PS] C:\>
You must provide a value expression on the right-hand side of the '-like' operator.
At C:\powershell.ps1:1 char:104
+ AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like <<<< *cart*)
-or ($_.Displayname -like *anna*) -or ($_.Displayname -like *robert*)}
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : ExpectedValueExpression
[PS] C:\>
Ohh...i missed the quotes.
it must be like "*cart*"
it must be like "*cart*"
Please note that this condition will skip all the mailboxes which has the words "cart" or "anna" or "robert" in any part of the displayname.
ASKER
:( see error below;
[PS] C:\>.\powershell.ps1
The term 'AllMailboxes' is not recognized as the name of a cmdlet, function, script file, or operable program. Check th
e spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\powershell.ps1:1 char:13
+ AllMailboxes <<<< = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like "carl")
-or ($_.Displayname -like "anna") -or ($_.Displayname -like "robert")}
+ CategoryInfo : ObjectNotFound: (AllMailboxes:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
[PS] C:\>
[PS] C:\>.\powershell.ps1
The term 'AllMailboxes' is not recognized as the name of a cmdlet, function, script file, or operable program. Check th
e spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\powershell.ps1:1 char:13
+ AllMailboxes <<<< = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like "carl")
-or ($_.Displayname -like "anna") -or ($_.Displayname -like "robert")}
+ CategoryInfo : ObjectNotFound: (AllMailboxes:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
[PS] C:\>
You missed $ before AllMailboxes. Also, you removed asterisk (*). If you remove this you may not get correct results.
The first line must be
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like "*carl*")
-or ($_.Displayname -like "*anna*") -or ($_.Displayname -like "*robert*")}
The first line must be
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like "*carl*")
-or ($_.Displayname -like "*anna*") -or ($_.Displayname -like "*robert*")}
ASKER
The command is running without errors however the mailbox quotas are not working correctly. All mailboxes are configured with the same quota; -IssueWarningQuota 2048MB -ProhibitSendQuota 4096MB -ProhibitSendReceiveQuota 4096MB
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics | where {($_.Displayname -like "*carl*") -or ($_.Displayname -like "*anna*") -or ($_.Displayname -like "*robert*")}
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics
foreach($Mailbox in $AllMailboxes){
$SizeMB = $Mailbox.TotalItemSize.Value.ToMB()
if(($SizeMB -lt 512) -or ($SizeMB -gt 256)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefaults $false -IssueWarningQuota 256MB -ProhibitSendQuota 512MB -ProhibitSendReceiveQuota 1024MB}
if(($SizeMB -lt 1048) -or ($SizeMB -gt 512)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefaults $false -IssueWarningQuota 512MB -ProhibitSendQuota 1024MB -ProhibitSendReceiveQuota 2048MB}
if(($SizeMB -lt 2048) -or ($SizeMB -gt 1024)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefaults $false -IssueWarningQuota 950MB -ProhibitSendQuota 2048MB -ProhibitSendReceiveQuota 2048MB}
if(($SizeMB -lt 3072) -or ($SizeMB -gt 2048)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefaults $false -IssueWarningQuota 1024MB -ProhibitSendQuota 3072MB -ProhibitSendReceiveQuota 3072MB}
if(($SizeMB -lt 4096) -or ($SizeMB -gt 3072)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefaults $false -IssueWarningQuota 2048MB -ProhibitSendQuota 4096MB -ProhibitSendReceiveQuota 4096MB}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Any idea what were the limits for those Cara, Anna and Robert. They must be updated to old values as they were not skipped in your script.
ASKER
The script is running but is not updating anyone's mailbox quotas ?
ASKER
let me try again
ASKER
It is applying correctly but "use mailbox database defaults" is still enabled for the users.
Ok..The parameter i gave was for Exchange 2007.
Instead of UseDatabaseRetentionDefaul ts $false, please set it to UseDatabaseQuotaDefaults $false
Instead of UseDatabaseRetentionDefaul
ASKER
You have been amazing. Thank you so much. Truly an expert
Prefect. My pleasure :) Nice learning
ASKER
Hi Rajitha14
Can you help with this?
https://www.experts-exchange.com/questions/27954559/Exchange-2010-Powershell-Exclude-members-of-a-distribution-group-from-working-Quota-script.html
Can you help with this?
https://www.experts-exchange.com/questions/27954559/Exchange-2010-Powershell-Exclude-members-of-a-distribution-group-from-working-Quota-script.html
$AllMailboxes = Get-Mailbox -resultsize unlimited | Get-MailboxStatistics
foreach($Mailbox in $AllMailboxes){
$SizeMB = $Mailbox.TotalItemSize.Val
if(($SizeMB -lt 2048) -or ($SizeMB -gt 1024)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefau
if(($SizeMB -lt 3072) -or ($SizeMB -gt 2048)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefau
if(($SizeMB -lt 4096) -or ($SizeMB -gt 3072)){Set-Mailbox $Mailbox.DisplayName -UseDatabaseRetentionDefau
}