Public/ConnectedSystems/Get-JIMConnectedSystemPasswordSynchronisation.ps1

# Copyright (c) Tetron Limited. All rights reserved.
# Licensed under the Tetron Commercial License. See LICENSE file in the project root.

function Get-JIMConnectedSystemPasswordSynchronisation {
    <#
    .SYNOPSIS
        Gets a Connected System's Password Synchronisation configuration.
 
    .DESCRIPTION
        Reports whether a Connected System receives synchronised passwords, and the settings governing how
        hard JIM tries to deliver them.
 
        A Connected System that has never been configured is reported with Configured set to false and JIM's
        defaults in the remaining fields, rather than as an error: that is exactly how such a system behaves,
        and a caller comparing settings across systems should not have to special-case the untouched ones.
 
        ConnectorSupportsPasswordSet says whether a configuration can be saved here at all. Password
        Synchronisation is only available on Connected Systems whose Connector can set passwords.
 
        Nothing returned here carries a password. Queued password changes are held encrypted and are never
        returned by any surface.
 
    .PARAMETER Id
        The ID of the Connected System.
 
    .PARAMETER InputObject
        A Connected System from Get-JIMConnectedSystem, through the pipeline.
 
    .OUTPUTS
        The Connected System's Password Synchronisation configuration, or JIM's defaults with Configured $false when
        it has none.
 
    .EXAMPLE
        Get-JIMConnectedSystemPasswordSynchronisation -Id 3
 
        Shows whether Connected System 3 receives synchronised passwords.
 
    .EXAMPLE
        Get-JIMConnectedSystem | ForEach-Object {
            $p = Get-JIMConnectedSystemPasswordSynchronisation -Id $_.Id
            [PSCustomObject]@{ System = $_.Name; Configured = $p.configured; Enabled = $p.enabled }
        }
 
        Audits which Connected Systems are set up for Password Synchronisation, and which are switched on.
 
    .LINK
        Set-JIMConnectedSystemPasswordSynchronisation
        Get-JIMConnectedSystemPasswordPolicy
    #>

    [CmdletBinding(DefaultParameterSetName = 'ById')]
    [OutputType('JIM.ConnectedSystemPasswordSynchronisationResponse')]
    param(
        [Parameter(Mandatory, ParameterSetName = 'ById', ValueFromPipelineByPropertyName)]
        [int]$Id,

        [Parameter(Mandatory, ParameterSetName = 'ByInputObject', ValueFromPipeline)]
        [PSCustomObject]$InputObject
    )

    process {
        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
        }

        $connectedSystemId = if ($PSCmdlet.ParameterSetName -eq 'ByInputObject') { $InputObject.Id } else { $Id }

        try {
            Invoke-JIMApi -Endpoint "/api/v1/synchronisation/connected-systems/$connectedSystemId/password-synchronisation" -Method 'GET'
        }
        catch {
            Write-Error "Failed to get the Password Synchronisation configuration for Connected System ${connectedSystemId}: $_"
        }
    }
}