Public/Set-IAMCoreSyncRule.ps1
|
function Set-IAMCoreSyncRule { [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter(Mandatory = $true)] [ValidatePattern("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")] # Is a guid connector object id [string]$Id, [Parameter(Mandatory = $false)] [string]$Description, [Parameter(Mandatory = $false)] [string]$JoinScope = "default", [Parameter(Mandatory = $false)] [boolean]$ProvisioningEnabled, [Parameter(Mandatory = $false)] [boolean]$ScheduleEnabled, [Parameter(Mandatory = $false)] [ValidateSet("Identity", "Relationship", "OrgUnit")] [string]$CoreObjectType, [Parameter(Mandatory = $false)] [string]$ConnectorObjectType, [Parameter(Mandatory = $false)] [System.Collections.Specialized.OrderedDictionary[]] $Scope = $null, [Parameter(Mandatory = $false)] [System.Collections.Specialized.OrderedDictionary[]] $InboundAttributeFlows, [Parameter(Mandatory = $false)] [int] $Priority = (Get-Random -Minimum 100 -Maximum 1000) ) $Existing = Get-IAMCoreSyncRule -Id $Id if (!$Existing.Id) { throw "IAM Core Sync Rule $Id not found" } $Existing = $Existing | ConvertTo-Json -Depth 100 | ConvertFrom-Json -Depth 100 -AsHashtable if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Description")) { $Existing.Description = $Description } if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("JoinScope")) { $Existing.JoinScope = $JoinScope } if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("ProvisioningEnabled")) { $Existing.ProvisioningEnabled = $ProvisioningEnabled } if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("ScheduleEnabled")) { $Existing.ScheduleEnabled = $ScheduleEnabled } if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("CoreObjectType")) { $Existing.CoreObjectType = $CoreObjectType } if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("ConnectorObjectType")) { $Existing.ConnectorObjectType = $ConnectorObjectType } if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Scope")) { $Existing.Scope = $Scope } if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("InboundAttributeFlows")) { $Existing.InboundAttributeFlows = $InboundAttributeFlows } if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Priority")) { $Existing.Priority = $Priority } if ($PSCmdlet.ShouldProcess("Updating IAM Core sync rule '$Id'")) { $Body = $Existing | ConvertTo-Json -Depth 100 $Result = Invoke-RestMethod -Uri "$Script:APIRoot/sync/syncrules/$Id" -Headers (Get-IAMCoreHeader) -Method Put -Body $Body -ContentType "application/json" if ($Result.IsSuccess) { return $Result.Data } else { throw "Failed to create IAM Core sync rule: $($Result.ErrorMessage)" } } } |