Skip to content

Commit ea04249

Browse files
committed
New function for add/edit quarantine policies and global settings
1 parent 9b939c5 commit ea04249

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
function Set-CIPPQuarantinePolicy {
2+
<#
3+
.SYNOPSIS
4+
Set/Add Quarantine policy, supports both custom and global Quarantine Policy
5+
6+
.DESCRIPTION
7+
Set/Add Quarantine policy, supports both custom and global Quarantine Policy
8+
9+
.PARAMETER identity
10+
Identity of the Quarantine policy to set, Name or GUID.
11+
12+
.PARAMETER action
13+
Which action to perform Create or Update. Valid values are Add, New, Create, Edit, Set, Update.
14+
15+
.PARAMETER tenantFilter
16+
Tenant to manage quarantine policy for.
17+
18+
.PARAMETER EndUserQuarantinePermissions
19+
End user quarantine permissions to set. This is a hashtable with the following keys:
20+
PermissionToBlockSender
21+
PermissionToDelete
22+
PermissionToPreview
23+
PermissionToRelease
24+
PermissionToRequestRelease
25+
PermissionToAllowSender
26+
PermissionToViewHeader
27+
PermissionToDownload
28+
29+
.PARAMETER APIName
30+
Name of the API executing the command.
31+
32+
.PARAMETER ESNEnabled
33+
Whether the quarantine notification is enabled or not.
34+
35+
.PARAMETER IncludeMessagesFromBlockedSenderAddress
36+
Whether to include messages from blocked sender address or not.
37+
38+
#>
39+
[CmdletBinding(DefaultParameterSetName = 'QuarantinePolicy')]
40+
param(
41+
[Parameter(Mandatory, ParameterSetName = 'QuarantinePolicy')]
42+
[Parameter(Mandatory, ParameterSetName = 'GlobalQuarantinePolicy')]
43+
[ValidateNotNullOrEmpty()]
44+
[string]$identity,
45+
46+
[Parameter(Mandatory, ParameterSetName = 'QuarantinePolicy')]
47+
[ValidateSet("Add", "New", "Create", "Edit", "Set", "Update")]
48+
[string]$action,
49+
50+
[Parameter(Mandatory, ParameterSetName = 'QuarantinePolicy')]
51+
[Hashtable]$EndUserQuarantinePermissions,
52+
53+
[Parameter(Mandatory, ParameterSetName = 'QuarantinePolicy')]
54+
[bool]$ESNEnabled,
55+
56+
[Parameter(ParameterSetName = 'QuarantinePolicy')]
57+
[bool]$IncludeMessagesFromBlockedSenderAddress = $false,
58+
59+
[Parameter(Mandatory, ParameterSetName = 'GlobalQuarantinePolicy')]
60+
[TimeSpan]$EndUserSpamNotificationFrequency,
61+
62+
[Parameter(ParameterSetName = 'GlobalQuarantinePolicy')]
63+
[string]$EndUserSpamNotificationCustomFromAddress = "",
64+
65+
[Parameter(ParameterSetName = 'GlobalQuarantinePolicy')]
66+
[bool]$OrganizationBrandingEnabled = $false,
67+
68+
[Parameter(Mandatory)]
69+
[string]$tenantFilter,
70+
[string]$APIName = 'QuarantinePolicy'
71+
)
72+
73+
try {
74+
75+
switch ($PSCmdlet.ParameterSetName) {
76+
"GlobalQuarantinePolicy" {
77+
$cmdParams = @{
78+
Identity = $identity
79+
EndUserSpamNotificationFrequency = $EndUserSpamNotificationFrequency.ToString()
80+
EndUserSpamNotificationCustomFromAddress = $EndUserSpamNotificationCustomFromAddress
81+
OrganizationBrandingEnabled = $OrganizationBrandingEnabled
82+
# QuarantinePolicyType = 'GlobalQuarantinePolicy'
83+
}
84+
$cmdLet = 'Set-QuarantinePolicy'
85+
}
86+
"QuarantinePolicy" {
87+
$cmdParams = @{
88+
EndUserQuarantinePermissionsValue = Convert-QuarantinePermissionsValue -InputObject $EndUserQuarantinePermissions
89+
ESNEnabled = $ESNEnabled
90+
IncludeMessagesFromBlockedSenderAddress = $IncludeMessagesFromBlockedSenderAddress
91+
}
92+
93+
switch ($action) {
94+
{$_ -in @("Add", "New", "Create")} { $cmdParams.Add("Name", $identity) ; $cmdLet = 'New-QuarantinePolicy' }
95+
{$_ -in @("Edit", "Set", "Update")} { $cmdParams.Add("Identity", $identity) ; $cmdLet = 'Set-QuarantinePolicy' }
96+
Default {
97+
throw "Invalid action specified. Valid actions are: Add, New, Edit, Set, Update."
98+
}
99+
}
100+
}
101+
}
102+
103+
$null = New-ExoRequest -tenantid $tenantFilter -cmdlet $cmdLet -cmdParams $cmdParams -useSystemMailbox $true
104+
105+
} catch {
106+
$ErrorMessage = Get-CippException -Exception $_
107+
throw ($ErrorMessage.NormalizedError -replace '\|Microsoft.Exchange.Management.Tasks.ValidationException\|', '')
108+
}
109+
}

0 commit comments

Comments
 (0)