Converting certificate format to BASE 64 string using PowerShell

I was recently challenged with building an ARM template that uploads a certificate to a new website. The ARM provider is there and Instead of handling files, it supports the approach of convering the certificate to a BASE 64 string that could then be included in the ARM Template.

The PowerShell script below will take any certificate in .pfx format and convert it to an BASE 64 string, and output it to a .txt file


$bytes = [System.IO.File]::ReadAllBytes("C:\");

$b64 = [System.Convert]::ToBase64String($bytes);

[System.Io.File]::WriteAllText("C:\", $b64);


I hope it helps

Kind regards,