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, [Parameter(Mandatory = $false)] [string]$ConnectorId, [Parameter(Mandatory = $false)] [boolean]$ProvisioningEnabled, [Parameter(Mandatory = $false)] [ValidateSet("Identity", "Relationship", "OrgUnit")] [string]$CoreObjectType, [Parameter(Mandatory = $false)] [string]$ConnectorObjectType, [Parameter(Mandatory = $false)] [bool]$Disabled, [Parameter(Mandatory = $false)] [ValidateRange(-1, [int]::MaxValue)] [int]$StartIndex = -1, [Parameter(Mandatory = $false)] [System.Collections.Hashtable[]] $Scope, [Parameter(Mandatory = $false)] [System.Collections.Hashtable[]] $InboundAttributeFlows, [Parameter(Mandatory = $false)] [string] $NameSuffix = " (copy)" ) begin { $Script:StartIndex = $StartIndex } 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 if($Script:StartIndex -gt 0) { $Script:StartIndex += 1 } $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 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 = $Script:StartIndex -gt 0 ? $Script:StartIndex : (Get-Random -Minimum 100000 -Maximum 1000000) disabled = $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Disabled') ? $Disabled : $InputObject.disabled } | 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)" } } } } |