Skip to content

Commit 9c749ed

Browse files
authored
Merge pull request KelvinTegelaar#1660 from kris6673/issue4769
Fix. handling of "Unlimited" values in Send/Receive limits validation
2 parents e512537 + 518a8a7 commit 9c749ed

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardSendReceiveLimitTenant.ps1

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,23 @@ function Invoke-CIPPStandardSendReceiveLimitTenant {
5353

5454
try {
5555
$AllMailBoxPlans = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-MailboxPlan' |
56-
Select-Object DisplayName, MaxSendSize, MaxReceiveSize, GUID
57-
}
58-
catch {
59-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
60-
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the SendReceiveLimitTenant state for $Tenant. Error: $ErrorMessage" -Sev Error
56+
Select-Object DisplayName, MaxSendSize, MaxReceiveSize, GUID
57+
} catch {
58+
$ErrorMessage = Get-CippException -Exception $_
59+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the SendReceiveLimitTenant state for $Tenant. Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
6160
return
6261
}
6362

6463
$MaxSendSize = [int64]"$($Settings.SendLimit)MB"
6564
$MaxReceiveSize = [int64]"$($Settings.ReceiveLimit)MB"
6665

6766
$NotSetCorrectly = foreach ($MailboxPlan in $AllMailBoxPlans) {
67+
# Handle "Unlimited" values - treat them as not matching the desired limit.
68+
if ($MailboxPlan.MaxSendSize -match 'Unlimited' -or $MailboxPlan.MaxReceiveSize -match 'Unlimited') {
69+
$MailboxPlan
70+
continue
71+
}
72+
6873
$PlanMaxSendSize = [int64]($MailboxPlan.MaxSendSize -replace '.*\(([\d,]+).*', '$1' -replace ',', '')
6974
$PlanMaxReceiveSize = [int64]($MailboxPlan.MaxReceiveSize -replace '.*\(([\d,]+).*', '$1' -replace ',', '')
7075
if ($PlanMaxSendSize -ne $MaxSendSize -or $PlanMaxReceiveSize -ne $MaxReceiveSize) {
@@ -83,8 +88,8 @@ function Invoke-CIPPStandardSendReceiveLimitTenant {
8388
}
8489
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully set the tenant send($($Settings.SendLimit)MB) and receive($($Settings.ReceiveLimit)MB) limits" -sev Info
8590
} catch {
86-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
87-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to set the tenant send and receive limits. Error: $ErrorMessage" -sev Error
91+
$ErrorMessage = Get-CippException -Exception $_
92+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to set the tenant send and receive limits. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
8893
}
8994
} else {
9095
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant send($($Settings.SendLimit)MB) and receive($($Settings.ReceiveLimit)MB) limits are already set correctly" -sev Info

0 commit comments

Comments
 (0)