Public/Connect-CheckIDPasswordAgent.ps1

<#
.DESCRIPTION
    Connects to the CheckIDPasswordAgent service using the provided TenantID, AccessTokenProfile, Hostname, and AgentID.

.SYNOPSIS
    Connects to the CheckIDPasswordAgent service.

.EXAMPLE
    Import-Module EntraIDAccessToken
    Import-Module CheckIDPasswordAgent

    Add-EntraIDClientSecretAccessTokenProfile `
        -Resource "api://c61cb4dd-35bf-4db9-b152-58e223782c11/" `
        -TenantId "bb73082a-b74c-4d39-aec0-41c77d6f4850" `
        -ClientId "78f07963-ce55-4b23-b56a-2e13f2036d7f"

    Connect-CheckIDPasswordAgent -TenantID "bb73082a-b74c-4d39-aec0-41c77d6f4850" `
        -Hostname "dev-api.byfortytwo.com" `
        -AgentID "7931eafe-21fa-4f3f-8280-968f50647e2e" `
        -Verbose
#>

function Connect-CheckIDPasswordAgent {
    [CmdletBinding()]

    Param(
        # Access token profile to use for authentication. the EntraIDAccessToken module must be installed and imported.
        [Parameter(Mandatory = $false)]
        [string]$AccessTokenProfile = "default",

        # Hostname of the Fortytwo API service
        [Parameter(Mandatory = $false)]
        [Validateset("dev-api.byfortytwo.com", "api.fortytwo.io")]
        [string]$Hostname = "api.fortytwo.io",

        # Agent ID for the CheckIDPasswordAgent. The value should be static for a certain agent.
        [Parameter(Mandatory = $true)]
        [ValidateScript( { $_ -match "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" } )]
        [string]$AgentID,

        # Dummy parameter for backwards compatibility. The TenantID is now retrieved from the AccessTokenProfile.
        [Parameter(Mandatory = $false)]
        [string]$TenantID = $null
    )

    Process {
        $Script:AccessTokenProfile = $AccessTokenProfile
        $Script:Hostname = $Hostname
        $Script:AgentID = $AgentID
        $Script:TenantID = (Get-EntraIDAccessTokenProfile -Profile $AccessTokenProfile).TenantId

        Write-EventLog -LogName "Application" -Source "CheckIDPasswordAgent" -EventId 1103 -EntryType Information -Message "Connecting CheckIDPasswordAgent with AgentID $($Script:AgentID) to Hostname $($Script:Hostname) and TenantID $($Script:TenantID)" -ErrorAction Continue
        Register-CheckIDPasswordAgent
    }
}