Skip to content

Commit 5c6e401

Browse files
committed
feat: Add mailbox recipient limits standardization script
Add new PowerShell script to standardize mailbox recipient limits across tenants. This script will help enforce consistent recipient limits for mailboxes in the CIPP platform.
1 parent b579ef9 commit 5c6e401

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
function Invoke-CIPPStandardMailboxRecipientLimits {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
.COMPONENT
6+
(APIName) MailboxRecipientLimits
7+
.SYNOPSIS
8+
(Label) Set Mailbox Recipient Limits
9+
.DESCRIPTION
10+
(Helptext) Sets the maximum number of recipients that can be specified in the To, Cc, and Bcc fields of a message for all mailboxes in the tenant.
11+
(DocsDescription) This standard configures the recipient limits for all mailboxes in the tenant. The recipient limit determines the maximum number of recipients that can be specified in the To, Cc, and Bcc fields of a message. This helps prevent spam and manage email flow.
12+
.NOTES
13+
CAT
14+
Exchange Standards
15+
TAG
16+
ADDEDCOMPONENT
17+
{"type":"number","name":"standards.MailboxRecipientLimits.RecipientLimit","label":"Recipient Limit","defaultValue":500}
18+
IMPACT
19+
Low Impact
20+
ADDEDDATE
21+
2025-05-28
22+
POWERSHELLEQUIVALENT
23+
Set-Mailbox -RecipientLimits
24+
RECOMMENDEDBY
25+
"CIPP"
26+
#>
27+
28+
param($Tenant, $Settings)
29+
30+
# Input validation
31+
if ([Int32]$Settings.RecipientLimit -lt 0 -or [Int32]$Settings.RecipientLimit -gt 10000) {
32+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'MailboxRecipientLimits: Invalid RecipientLimit parameter set. Must be between 0 and 10000.' -sev Error
33+
return
34+
}
35+
36+
# Get all mailboxes in the tenant
37+
$Mailboxes = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-Mailbox' -cmdParams @{ResultSize = 'Unlimited' }
38+
39+
# Check which mailboxes need to be updated
40+
$MailboxesToUpdate = $Mailboxes | Where-Object { $_.RecipientLimits -ne $Settings.RecipientLimit }
41+
42+
# Remediation
43+
if ($Settings.remediate -eq $true) {
44+
if ($MailboxesToUpdate.Count -gt 0) {
45+
try {
46+
foreach ($Mailbox in $MailboxesToUpdate) {
47+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-Mailbox' -cmdParams @{
48+
Identity = $Mailbox.Identity
49+
RecipientLimits = $Settings.RecipientLimit
50+
}
51+
}
52+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Successfully set recipient limits to $($Settings.RecipientLimit) for $($MailboxesToUpdate.Count) mailboxes" -sev Info
53+
}
54+
catch {
55+
$ErrorMessage = Get-CippException -Exception $_
56+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set recipient limits. $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
57+
}
58+
}
59+
else {
60+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "All mailboxes already have the correct recipient limit of $($Settings.RecipientLimit)" -sev Info
61+
}
62+
}
63+
64+
# Alert
65+
if ($Settings.alert -eq $true) {
66+
if ($MailboxesToUpdate.Count -eq 0) {
67+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "All mailboxes have the correct recipient limit of $($Settings.RecipientLimit)" -sev Info
68+
}
69+
else {
70+
Write-StandardsAlert -message "Found $($MailboxesToUpdate.Count) mailboxes with incorrect recipient limits" -object $MailboxesToUpdate -tenant $Tenant -standardName 'MailboxRecipientLimits' -standardId $Settings.standardId
71+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Found $($MailboxesToUpdate.Count) mailboxes with incorrect recipient limits" -sev Info
72+
}
73+
}
74+
75+
# Report
76+
if ($Settings.report -eq $true) {
77+
Add-CIPPBPAField -FieldName 'MailboxRecipientLimits' -FieldValue $MailboxesToUpdate -StoreAs json -Tenant $Tenant
78+
79+
if ($MailboxesToUpdate.Count -eq 0) {
80+
$FieldValue = $true
81+
}
82+
else {
83+
$FieldValue = $MailboxesToUpdate
84+
}
85+
Set-CIPPStandardsCompareField -FieldName 'standards.MailboxRecipientLimits' -FieldValue $FieldValue -Tenant $Tenant
86+
}
87+
}

0 commit comments

Comments
 (0)