Skip to content

Commit f980c13

Browse files
committed
Add Exchange Recipient Limits Management
Adds new HTTP function `Invoke-ExecSetRecipientLimits` to manage Exchange mailbox recipient limits through the CIPP API. The function allows setting recipient limits for specific mailboxes with proper error handling and logging.
1 parent 13591ae commit f980c13

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function Invoke-ExecSetRecipientLimits {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
.ROLE
6+
Exchange.Mailbox.ReadWrite
7+
#>
8+
[CmdletBinding()]
9+
param($Request, $TriggerMetadata)
10+
11+
$APIName = $Request.Params.CIPPEndpoint
12+
$Headers = $Request.Headers
13+
Write-LogMessage -Headers $Headers -API $APIName -tenant $TenantFilter -message 'Accessed this API' -Sev 'Debug'
14+
15+
# Interact with the query or body of the request
16+
$TenantFilter = $Request.Body.tenantFilter
17+
$recipientLimit = $Request.Body.recipientLimit
18+
$Identity = $Request.Body.Identity
19+
$UserPrincipalName = $Request.Body.userid
20+
21+
# Set the parameters for the EXO request
22+
$ExoRequest = @{
23+
tenantid = $TenantFilter
24+
cmdlet = 'Set-Mailbox'
25+
cmdParams = @{
26+
Identity = $Identity
27+
RecipientLimits = $recipientLimit
28+
}
29+
}
30+
31+
# Execute the EXO request
32+
try {
33+
$null = New-ExoRequest @ExoRequest
34+
$Results = "Recipient limit for $UserPrincipalName has been set to $recipientLimit"
35+
36+
Write-LogMessage -API $APIName -tenant $TenantFilter -message $Results -sev Info
37+
$StatusCode = [HttpStatusCode]::OK
38+
} catch {
39+
$ErrorMessage = Get-CippException -Exception $_
40+
$Results = "Could not set recipient limit for $UserPrincipalName to $recipientLimit. Error: $($ErrorMessage.NormalizedError)"
41+
Write-LogMessage -API $APIName -tenant $TenantFilter -message $Results -sev Error -LogData $ErrorMessage
42+
$StatusCode = [HttpStatusCode]::InternalServerError
43+
}
44+
45+
# Associate values to output bindings by calling 'Push-OutputBinding'.
46+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
47+
StatusCode = $StatusCode
48+
Body = @{ Results = $Results }
49+
})
50+
}

0 commit comments

Comments
 (0)