Use the [System.Convert] .NET Class to convert an array of Byte objects to a Base64 string.
Get bytes into a variable using the Get-Content cmdlet.
The parameters depend on whether you are using Windows PowerShell or PowerShell version 6 or later (previously called PowerShell Core).
$arrayOfBytes = Get-Content c:\path\to\binary\file.bin -Encoding Byte -Raw$arrayOfBytes = Get-Content c:\path\to\binary\file.bin -ReadCount 0 -AsByteStreamUse the ToBase64String method to convert to the Base64 string.
$base64string = [System.Convert]::ToBase64String($arrayOfBytes)To get back to a binary file, use the FromBase64String method.
[System.Convert]::FromBase64String($base64string) |
Set-Content -Path c:\new\path\to\binary\file.bin -Encoding Byte- Convert documentation
- For more on
Get-ContentandSet-Contentreference help in PowerShell. e.g.Get-Help Get-Content -Full