Private/Read-NSPEntraConnectState.ps1

function Read-NSPEntraConnectState {
    <#
    .SYNOPSIS
        Reads the rules, connectors and global setting from the local ADSync module. Read-only.
    #>

    [CmdletBinding()]
    param()

    if (-not (Get-Module -ListAvailable -Name ADSync)) {
        throw 'The ADSync module is not available. Run this on the Entra Connect Sync server.'
    }
    $module = Import-Module ADSync -PassThru -ErrorAction Stop

    # Availability differs between builds, and a missing setting does not stop the rule review.
    $parameters = @()
    if (Get-Command Get-ADSyncGlobalSettingsParameter -ErrorAction SilentlyContinue) {
        try { $parameters = @(Get-ADSyncGlobalSettingsParameter) }
        catch { Write-Warning "Global settings were not readable: $($_.Exception.Message)" }
    }

    @{
        Rule = @(Get-ADSyncRule)
        Connector = @(Get-ADSyncConnector)
        GlobalParameter = $parameters
        ModuleVersion = [string]$module.Version
    }
}