Skip to content

Commit

Permalink
added overwrite if rule exists
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Feb 28, 2023
1 parent d546b7f commit f1601e9
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions AddTransportRule/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,28 @@ param($Request, $TriggerMetadata)
$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"

$RequestParams = $Request.Body.PowerShellCommand | ConvertFrom-Json | Select-Object -Property * -ExcludeProperty GUID
$RequestParams = $Request.Body.PowerShellCommand | ConvertFrom-Json | Select-Object -Property * -ExcludeProperty GUID, Comments

$Tenants = ($Request.body | Select-Object Select_*).psobject.properties.value
$Result = foreach ($Tenantfilter in $tenants) {
$Existing = New-ExoRequest -ErrorAction SilentlyContinue -tenantid $Tenantfilter -cmdlet "Get-TransportRule" -useSystemMailbox $true | Where-Object -Property Identity -EQ $RequestParams.name
try {
$GraphRequest = New-ExoRequest -tenantid $Tenantfilter -cmdlet "New-TransportRule" -cmdParams $RequestParams
"Successfully created transport rule for $tenantfilter."
if ($Existing) {
Write-Host "Found existing"
$RequestParams | Add-Member -NotePropertyValue $RequestParams.name -NotePropertyName Identity
$GraphRequest = New-ExoRequest -tenantid $Tenantfilter -cmdlet "Set-TransportRule" -cmdParams ($RequestParams | Select-Object -Property * -ExcludeProperty UseLegacyRegex) -useSystemMailbox $true
"Successfully set transport rule for $tenantfilter."
}
else {
Write-Host "Creating new"
$GraphRequest = New-ExoRequest -tenantid $Tenantfilter -cmdlet "New-TransportRule" -cmdParams $RequestParams -useSystemMailbox $true
"Successfully created transport rule for $tenantfilter."
}

Write-LogMessage -API $APINAME -tenant $tenantfilter -message "Created transport rule for $($tenantfilter)" -sev Debug
}
catch {
"Could not create created transport rule for $($tenantfilter): $($_.Exception.message)"
"Could not create transport rule for $($tenantfilter): $($_.Exception.message)"
}
}

Expand Down

0 comments on commit f1601e9

Please sign in to comment.