private/convert-to/ConvertTo-SessionManagerPluginArgument.ps1

function ConvertTo-SessionManagerPluginArgument
{
    [CmdletBinding(PositionalBinding = $true)]
    [OutputType([String])]
    param(
        [Parameter(Mandatory = $true)]
        [ValidatePattern('^(af|il|ap|ca|eu|me|sa|us|cn|us-gov|us-iso|us-isob)-(central|north|(north(?:east|west))|south|south(?:east|west)|east|west)-\d{1}$')]
        [string] $Region,
        [Parameter(Mandatory = $true)]
        [psobject] $SsmSession,
        [Parameter(Mandatory = $true)]
        [psobject] $SsmCommand
    )

    $ssmSessionJson = @{
        SessionId  = $SsmSession.SessionId
        TokenValue = $SsmSession.TokenValue
        StreamUrl  = $SsmSession.StreamUrl
    } | ConvertTo-Json -Compress

    $argumentList = @(
        # session response
        $ssmSessionJson,
        # client region
        $Region,
        # operation name
        'StartSession',
        # profile name from aws credentials/config files
        '',
        # parameters input to aws cli for StartSession api
        ($SsmCommand | ConvertTo-Json -Compress),
        # endpoint for ssm service
        "https://ssm.$Region.amazonaws.com"
    )

    $result = ($argumentList | ForEach-Object { "`"$($_ -replace @('"', '\"'))`"" }) -join ' '

    return $result
}