Skip to content

Commit 2c189b2

Browse files
committed
Refactor mailbox recipient limits script to improve efficiency and accuracy. Consolidated mailbox plan retrieval and updated filtering logic to ensure only relevant mailboxes are processed based on recipient limits.
1 parent 526bea6 commit 2c189b2

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,29 @@ function Invoke-CIPPStandardMailboxRecipientLimits {
3333
return
3434
}
3535

36-
# Get all mailboxes and their associated mailbox plans in a single batch
36+
# Get mailbox plans first
37+
$MailboxPlans = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-MailboxPlan' -cmdParams @{ ResultSize = 'Unlimited' }
38+
39+
# Create a hashtable of mailbox plans for quick lookup
40+
$MailboxPlanLookup = @{}
41+
foreach ($Plan in $MailboxPlans) {
42+
$MailboxPlanLookup[$Plan.Guid] = $Plan
43+
}
44+
45+
# Get mailboxes that need updating (either different from target limit or have "Unlimited" set)
3746
$Requests = @(
3847
@{
3948
CmdletInput = @{
4049
CmdletName = 'Get-Mailbox'
41-
Parameters = @{ ResultSize = 'Unlimited' }
42-
}
43-
},
44-
@{
45-
CmdletInput = @{
46-
CmdletName = 'Get-MailboxPlan'
47-
Parameters = @{ ResultSize = 'Unlimited' }
50+
Parameters = @{
51+
ResultSize = 'Unlimited'
52+
Filter = "RecipientLimits -ne '$($Settings.RecipientLimit)' -or RecipientLimits -eq 'Unlimited'"
53+
}
4854
}
4955
}
5056
)
5157

52-
$Results = New-ExoBulkRequest -tenantid $Tenant -cmdletArray $Requests
53-
$Mailboxes = $Results.GetMailbox
54-
$MailboxPlans = $Results.GetMailboxPlan
55-
56-
# Create a hashtable of mailbox plans for quick lookup
57-
$MailboxPlanLookup = @{}
58-
foreach ($Plan in $MailboxPlans) {
59-
$MailboxPlanLookup[$Plan.Guid] = $Plan
60-
}
58+
$Mailboxes = New-ExoBulkRequest -tenantid $Tenant -cmdletArray $Requests
6159

6260
# Process mailboxes and categorize them based on their plan limits
6361
$MailboxResults = $Mailboxes | ForEach-Object {

0 commit comments

Comments
 (0)