Public/SyncRules/Get-JIMSyncRule.ps1
|
# Copyright (c) Tetron Limited. All rights reserved. # Licensed under the Tetron Commercial License. See LICENSE file in the project root. function Get-JIMSyncRule { <# .SYNOPSIS Gets Synchronisation Rules from JIM. .DESCRIPTION Retrieves Synchronisation Rule configurations from JIM. Can retrieve all rules, a specific rule by ID, or filter by Connected System. .PARAMETER Id The unique identifier of a specific Synchronisation Rule to retrieve. .PARAMETER ConnectedSystemId Filter Synchronisation Rules by Connected System ID. .PARAMETER ConnectedSystemName Filter Synchronisation Rules by Connected System name. Must be an exact match. .PARAMETER Name Filter Synchronisation Rules by name. Supports wildcards (e.g., "Inbound*"). .OUTPUTS PSCustomObject representing Synchronisation Rule(s). .EXAMPLE Get-JIMSyncRule Gets all Synchronisation Rules. .EXAMPLE Get-JIMSyncRule -Id 1 Gets the Synchronisation Rule with ID 1. .EXAMPLE Get-JIMSyncRule -ConnectedSystemId 1 Gets all Synchronisation Rules for Connected System ID 1. .EXAMPLE Get-JIMSyncRule -ConnectedSystemName 'Contoso AD' Gets all Synchronisation Rules for the Connected System named 'Contoso AD'. .EXAMPLE Get-JIMSyncRule -Name "Inbound*" Gets all Synchronisation Rules with names starting with "Inbound". .EXAMPLE Get-JIMConnectedSystem -Name "HR*" | Get-JIMSyncRule Gets all Synchronisation Rules for Connected Systems with names starting with "HR". .LINK New-JIMSyncRule Set-JIMSyncRule Remove-JIMSyncRule #> [CmdletBinding(DefaultParameterSetName = 'List')] [OutputType([PSCustomObject])] param( [Parameter(Mandatory, ParameterSetName = 'ById')] [int]$Id, [Parameter(ParameterSetName = 'List', ValueFromPipelineByPropertyName)] [Parameter(ParameterSetName = 'ByConnectedSystemId')] [int]$ConnectedSystemId, [Parameter(ParameterSetName = 'ByConnectedSystemName')] [string]$ConnectedSystemName, [Parameter(ParameterSetName = 'List')] [Parameter(ParameterSetName = 'ByConnectedSystemId')] [Parameter(ParameterSetName = 'ByConnectedSystemName')] [SupportsWildcards()] [string]$Name ) process { # Check connection first if (-not $script:JIMConnection) { Write-Error "You are not connected to JIM. Run Connect-JIM -Url <your JIM URL> to authenticate, then try again." return } # Resolve ConnectedSystemName to ConnectedSystemId if specified if ($PSBoundParameters.ContainsKey('ConnectedSystemName')) { $connectedSystem = Resolve-JIMConnectedSystem -Name $ConnectedSystemName $ConnectedSystemId = $connectedSystem.id } switch ($PSCmdlet.ParameterSetName) { 'ById' { Write-Verbose "Getting Synchronisation Rule with ID: $Id" $result = Invoke-JIMApi -Endpoint "/api/v1/synchronisation/sync-rules/$Id" $result } default { Write-Verbose "Getting all Synchronisation Rules" $response = Invoke-JIMApi -Endpoint "/api/v1/synchronisation/sync-rules" # Handle paginated response - check if 'items' property exists (not if it's truthy) $rules = if ($null -ne $response.items) { $response.items } else { $response } # Filter by Connected System if specified if ($PSBoundParameters.ContainsKey('ConnectedSystemId') -or $PSBoundParameters.ContainsKey('ConnectedSystemName')) { Write-Verbose "Filtering by Connected System ID: $ConnectedSystemId" $rules = $rules | Where-Object { $_.connectedSystemId -eq $ConnectedSystemId } } # Filter by name if specified if ($Name) { Write-Verbose "Filtering by name pattern: $Name" $rules = $rules | Where-Object { $_.name -like $Name } } # Output each rule individually for pipeline support foreach ($rule in $rules) { $rule } } } } } |