Public/Copy-IAMCoreSyncRule.ps1
|
function Copy-IAMCoreSyncRule { [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] $InputObject, [Parameter(Mandatory = $false)] [string]$Name, [Parameter(Mandatory = $false)] [string]$Description, [Parameter(Mandatory = $false)] [string]$JoinScope = "default", [Parameter(Mandatory = $false)] [string]$ConnectorId, [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.Hashtable[]] $Scope, [Parameter(Mandatory = $false)] [System.Collections.Hashtable[]] $InboundAttributeFlows, [Parameter(Mandatory = $false)] [int] $Priority = (Get-Random -Minimum 100000 -Maximum 1000000), [Parameter(Mandatory = $false)] [string] $NameSuffix = " (copy)" ) process { $CalculatedName = [string]::IsNullOrEmpty($Name) ? ($InputObject.name + $NameSuffix) : $Name if ($PSCmdlet.ShouldProcess("Creating IAM Core sync rule '$CalculatedName'")) { # Validate whether name was specified through pipeline or manually $Body = @{ name = $CalculatedName description = [string]::IsNullOrEmpty($Description) ? $InputObject.description : $Description connectorId = [string]::IsNullOrEmpty($ConnectorId) ? $InputObject.connectorId : $ConnectorId provisioningEnabled = $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('ProvisioningEnabled') ? $ProvisioningEnabled : $InputObject.provisioningEnabled scheduleEnabled = $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('ScheduleEnabled') ? $ScheduleEnabled : $InputObject.scheduleEnabled coreObjectType = [string]::IsNullOrEmpty($CoreObjectType) ? $InputObject.coreObjectType : $CoreObjectType connectorObjectType = [string]::IsNullOrEmpty($ConnectorObjectType) ? $InputObject.connectorObjectType : $ConnectorObjectType scope = $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Scope') ? $Scope : $InputObject.scope joinScope = [string]::IsNullOrEmpty($JoinScope) ? $InputObject.joinScope : $JoinScope inboundAttributeFlows = $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('InboundAttributeFlows') ? $InboundAttributeFlows : $InputObject.inboundAttributeFlows priority = $Priority } | ConvertTo-Json -Depth 100 $Result = Invoke-RestMethod -Uri "$Script:APIRoot/sync/syncrules" -Headers (Get-IAMCoreHeader) -Method Post -Body $Body -ContentType "application/json" -SkipHttpErrorCheck -StatusCodeVariable "statuscode" if ($Result.IsSuccess) { return $Result.Data } else { throw "Failed to create IAM Core sync rule (Status code $statuscode): $($Result)" } } } } |