Private/Resolve-SIAUri.ps1

function Resolve-SIAUri {
    <#
    Builds the full request URI for a SIA API call. CyberArk splits SIA-related
    operations across four hosts under the same tenant subdomain; Service
    selects which one a given cmdlet needs.
    #>

    [CmdletBinding()]
    [OutputType([uri])]
    param(
        [Parameter(Mandatory)]
        [string]$Path,

        [ValidateSet('Dpa', 'Uap', 'Uar', 'UserPortal')]
        [string]$Service = 'Dpa',

        [Parameter(Mandatory)]
        [string]$Subdomain,

        [hashtable]$QueryParameter
    )

    $hostBySer = @{
        Dpa        = "$Subdomain.dpa.cyberark.cloud"
        Uap        = "$Subdomain.uap.cyberark.cloud"
        Uar        = "$Subdomain.uar.cyberark.cloud"
        UserPortal = "$Subdomain-userportal.cyberark.cloud"
    }

    $builder = [System.UriBuilder]::new('https', $hostBySer[$Service])
    $builder.Path = '/' + $Path.TrimStart('/')

    if ($QueryParameter -and $QueryParameter.Count -gt 0) {
        $pairs = @(foreach ($key in $QueryParameter.Keys) {
                $value = $QueryParameter[$key]
                if ($null -ne $value) {
                    '{0}={1}' -f [uri]::EscapeDataString($key), [uri]::EscapeDataString([string]$value)
                }
            })
        if ($pairs.Count -gt 0) {
            $builder.Query = '?' + ($pairs -join '&')
        }
    }

    $builder.Uri
}