Skip to content

Commit 058d8ef

Browse files
committed
feat: Add Invoke-ExecSetMailboxEmailSize and Set-CippMaxEmailSize functions to set max send/receive size for mailboxes
1 parent 1efed26 commit 058d8ef

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using namespace System.Net
2+
3+
Function Invoke-ExecSetMailboxEmailSize {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Exchange.Mailbox.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $Request.Params.CIPPEndpoint
14+
$Headers = $Request.Headers
15+
Write-LogMessage -Headers $User -API $APIName -message 'Accessed this API' -Sev 'Debug'
16+
17+
# Interact with query parameters or the body of the request.
18+
$Tenant = $Request.Body.tenantFilter
19+
$UserPrincipalName = $Request.Body.UPN
20+
$UserID = $Request.Body.id
21+
$MaxSendSize = $Request.Body.maxSendSize
22+
$MaxReceiveSize = $Request.Body.maxReceiveSize
23+
24+
try {
25+
$Params = @{
26+
TenantFilter = $Tenant
27+
APIName = $APIName
28+
Headers = $Headers
29+
UserPrincipalName = $UserPrincipalName
30+
UserID = $UserID
31+
MaxSendSize = $MaxSendSize
32+
MaxReceiveSize = $MaxReceiveSize
33+
}
34+
if ([string]::IsNullOrWhiteSpace($MaxSendSize)) { $Params.Remove('MaxSendSize') }
35+
if ([string]::IsNullOrWhiteSpace($MaxReceiveSize)) { $Params.Remove('MaxReceiveSize') }
36+
$Result = Set-CippMaxEmailSize @Params
37+
$StatusCode = [HttpStatusCode]::OK
38+
} catch {
39+
$Result = "$($_.Exception.Message)"
40+
$StatusCode = [HttpStatusCode]::InternalServerError
41+
}
42+
43+
# Associate values to output bindings by calling 'Push-OutputBinding'.
44+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
45+
StatusCode = $StatusCode
46+
Body = @{ Results = $Result }
47+
})
48+
49+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function Set-CippMaxEmailSize {
2+
[CmdletBinding()]
3+
param (
4+
$Headers,
5+
$TenantFilter,
6+
$APIName = 'Mailbox Max Send/Receive Size',
7+
$UserPrincipalName,
8+
$UserID,
9+
[ValidateRange(1, 150)]
10+
[Int32]$MaxSendSize,
11+
[ValidateRange(1, 150)]
12+
[Int32]$MaxReceiveSize
13+
)
14+
15+
try {
16+
# Id the ID is provided, use it. Otherwise, use the UPN
17+
$Identity = $UserID ?? $UserPrincipalName
18+
if ([string]::IsNullOrWhiteSpace($Identity)) {
19+
$Result = 'No identity provided. Cannot set mailbox email max size.'
20+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Error -tenant $TenantFilter
21+
throw $Result
22+
}
23+
24+
if ($MaxSendSize -eq 0 -and $MaxReceiveSize -eq 0) {
25+
$Result = 'No max send or receive size provided. Cannot set mailbox email max size.'
26+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Error -tenant $TenantFilter
27+
throw $Result
28+
}
29+
30+
$cmdletParams = @{
31+
Identity = $Identity
32+
}
33+
# Set the max send and receive size if they are provided. Convert to bytes
34+
if ($MaxSendSize -gt 0) { $cmdletParams['MaxSendSize'] = $MaxSendSize * 1MB }
35+
if ($MaxReceiveSize -gt 0) { $cmdletParams['MaxReceiveSize'] = $MaxReceiveSize * 1MB }
36+
37+
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-Mailbox' -cmdParams $cmdletParams
38+
39+
# Use UPN for logging if provided
40+
$Identity = $UserPrincipalName ?? $UserID
41+
$Result = "Set mailbox email max size for $($Identity) to "
42+
if ($MaxSendSize -gt 0) { $Result += "Send: $($MaxSendSize)MB " }
43+
if ($MaxReceiveSize -gt 0) { $Result += "Receive: $($MaxReceiveSize)MB" }
44+
45+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Info -tenant $TenantFilter
46+
return $Result
47+
} catch {
48+
$ErrorMessage = Get-CippException -Exception $_
49+
50+
# Use UPN for logging if provided
51+
$Identity = $UserPrincipalName ?? $UserID
52+
$Result = "Failed to set mailbox email max size for $($Identity). Error: $($ErrorMessage)"
53+
54+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Error -tenant $TenantFilter -LogData $ErrorMessage
55+
throw $Result
56+
}
57+
}

0 commit comments

Comments
 (0)