Convert PFX SSL certificate to base64 in PowerShell and PowerShell Core.

Several resources in Azure requires sending the SSL cert data, you can get this by generating it from the SSL PFX file.

Regular powershell

$fileContentBytes = get-content 'your-cert.pfx' -Encoding Byte
[System.Convert]::ToBase64String($fileContentBytes) | Out-File pfx-encoded-bytes.txt

PowerShell Core

The first -Encoding Byte will cause an error in PowerShell Core, so you will actually neeed to use AsByteStream.

PowerShell Core Error

Set-Content : Cannot bind parameter Encoding. Cannot convert the Byte value of type System.String to type System.Text.Encoding.
$Set-Content -Path 'your-cert.pfx' -AsByteStream
[System.Convert]::ToBase64String($fileContentBytes) | Out-File pfx-encoded-bytes.txt