Find 365 mailboxes with prohibit send quota over 40GB and reduce

Hi all

I’m trying to run a powershell command that will find users with a ProhibitSendQuota over 40GB and then reduce the quota to the company standard 2.1GB limit. I have found the below command and has worked for any users over 9GB

Get-Mailbox -RecipientTypeDetails UserMailbox | ? {$_.ProhibitSendQuota -ge 9GB } | Set-Mailbox -ProhibitSendQuota 2.1GB -ProhibitSendReceiveQuota 2.5GB -IssueWarningQuota 2GB

However testing the first section just return the list of users: -

Get-Mailbox -RecipientTypeDetails UserMailbox | ? {$_.ProhibitSendQuota -ge 9GB }

If I change the 9GB to 40GB it returns results for anyone over 4GB, it seems to ignore everything but the first number.

Any help very much welcome or an alternate method.

Many Thanks in advance
Phil

Just out of curiosity, do you get the same result if you change the query to -gt (strict greater than) rather than -ge (greater than or equal)?

Yes, I increased to 10 and it is returning results for anyone with a quota over 1GB

That is strange. I am running the code as you have it above; testing both 1GB and 14GB (as a number of users are set to 1 or 14) and it filtered as one would expect.

(Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited | ? {$_.ProhibitSendQuota -gt 1GB}).Count
(Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited | ? {$_.ProhibitSendQuota -gt 14GB}).Count

4318
4262

Can you copy the code line you’re using in the console exactly like you’re using it and paste it here formatted as code using the preformatted text button ( </> ) ?

Don’t you get any errors?

Get-Mailbox -RecipientTypeDetails UserMailbox | ? {$_.ProhibitSendQuota -gt 40GB}

No errors just returning 2 users which have 4.5GB and 9.5GB quotas.

Tested adding “-ResultSize Unlimited” but same issue.
Also rebooted laptop and made sure running PowerShell as admin

Wow. That’s really weird. Would have expected at least 719 though. :wink:

Probably you already tried to list these 719 mailboxes and scanned their ProhibitSendQuota with the eyes. Are there actually some with more than 14GB?

So per the MS docs page’s example, have you tried wrapping your quota in quotes? Admittedly I cannot reproduce your issue even not using quotes, but would be worth a shot.

You can only use the Filter parameter to look for the value Unlimited for this property. For example, Get-Mailbox -Filter "ProhibitSendQuota -eq 'Unlimited'" or Get-Mailbox -Filter "ProhibitSendQuota -ne 'Unlimited'" .

You can’t use the Filter parameter to look for size values of this property. Instead, use this syntax: Get-Mailbox | where "$_.ProhibitSendQuota -<Operator> '<Size>'" . For example, Get-Mailbox | where "$_.ProhibitSendQuota -lt '70GB'" .

Notice the quotes in the suggestion where clause.

Tested and not returning anything even though all mailboxes are under 70GB

Playing around with the below

$Mailboxes = Get-Mailbox -ResultSize Unlimited | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Alias
foreach ($Mailbox in $Mailboxes){
    write-output $Mailbox.ProhibitSendQuota.substring(0,4)
}

Will get the command to return email address and then will be able to use an IF statement to check if the quota is over a certain value and then use the email address to run a command to reduce the quotas

$Mailboxes = Get-Mailbox -ResultSize Unlimited | Select UserPrincipalName, DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Alias
foreach ($Mailbox in $Mailboxes){
	$Inputstring =$Mailbox.ProhibitSendQuota.substring(0,4)
	$CharArray =$InputString.Split(" ")

	if ( [int]$CharArray[0] -gt 51)
	{
    	write-host $CharArray[0] + $Mailbox.UserPrincipalName
	Set-Mailbox $Mailbox.UserPrincipalName -ProhibitSendQuota 2.1GB -ProhibitSendReceiveQuota 2.5GB -IssueWarningQuota 2GB
	}
}

Working, sets anyone quota if they have a ProhibitSendQuota over 51GB

1 Like

Please do not post images of code as this is not helpful. Instead click on the preformatted text button ( </> ) and paste the code as text where you’ve been told.

And please do not add another post - edit the existing one and correct the formatting. :wink:

Thanks in advance.

Wish I knew 100% why the previous way wasn’t working for you, but glad you got it working.

This is because Exchange stores that property value as a string, so what you are asking the where to do is compare on a string to an int or int64 which won’t work.

❯ $mbx.ProhibitSendQuota.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String                                   System.Object

If you were using the Exchange snap-in OnPrem that presents a serialized value with multiple methods to convert it to bytes, MB, GB. But with a remote session which you have to do with Exchange Online then you just have a string .

As a workaround if you get a mailbox with the correct ‘prohibitsendquota’ string you can run a filter with that. This will only get you part of the way there but you can at least return fewer mailboxes to parse

 Get-Mailbox -Filter "ProhibitSendQuota -ne '99 GB (106,300,440,576 bytes)'"
 Get-EXOMailbox -Filter "ProhibitSendQuota -ne '99 GB (106,300,440,576 bytes)'"