File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -6,17 +6,28 @@ param($Request, $TriggerMetadata)
6
6
$APIName = $TriggerMetadata.FunctionName
7
7
Write-LogMessage - user $request.headers .' x-ms-client-principal' - API $APINAME - message " Accessed this API" - Sev " Debug"
8
8
9
- $RequestParams = $Request.Body.PowerShellCommand | ConvertFrom-Json | Select-Object - Property * - ExcludeProperty GUID
9
+ $RequestParams = $Request.Body.PowerShellCommand | ConvertFrom-Json | Select-Object - Property * - ExcludeProperty GUID, Comments
10
10
11
11
$Tenants = ($Request.body | Select-Object Select_* ).psobject.properties.value
12
12
$Result = foreach ($Tenantfilter in $tenants ) {
13
+ $Existing = New-ExoRequest - ErrorAction SilentlyContinue - tenantid $Tenantfilter - cmdlet " Get-TransportRule" - useSystemMailbox $true | Where-Object - Property Identity -EQ $RequestParams.name
13
14
try {
14
- $GraphRequest = New-ExoRequest - tenantid $Tenantfilter - cmdlet " New-TransportRule" - cmdParams $RequestParams
15
- " Successfully created transport rule for $tenantfilter ."
15
+ if ($Existing ) {
16
+ Write-Host " Found existing"
17
+ $RequestParams | Add-Member - NotePropertyValue $RequestParams.name - NotePropertyName Identity
18
+ $GraphRequest = New-ExoRequest - tenantid $Tenantfilter - cmdlet " Set-TransportRule" - cmdParams ($RequestParams | Select-Object - Property * - ExcludeProperty UseLegacyRegex) - useSystemMailbox $true
19
+ " Successfully set transport rule for $tenantfilter ."
20
+ }
21
+ else {
22
+ Write-Host " Creating new"
23
+ $GraphRequest = New-ExoRequest - tenantid $Tenantfilter - cmdlet " New-TransportRule" - cmdParams $RequestParams - useSystemMailbox $true
24
+ " Successfully created transport rule for $tenantfilter ."
25
+ }
26
+
16
27
Write-LogMessage - API $APINAME - tenant $tenantfilter - message " Created transport rule for $ ( $tenantfilter ) " - sev Debug
17
28
}
18
29
catch {
19
- " Could not create created transport rule for $ ( $tenantfilter ) : $ ( $_.Exception.message ) "
30
+ " Could not create transport rule for $ ( $tenantfilter ) : $ ( $_.Exception.message ) "
20
31
}
21
32
}
22
33
You can’t perform that action at this time.
0 commit comments