Skip to main content

How to convert a file to a base64 string in PowerShell.

# PowerShell 6+
[Convert]::ToBase64String((Get-Content '<filepath>' -AsByteStream -Raw))

# Windows PowerShell 5.1
[Convert]::ToBase64String((Get-Content '<filepath>' -Encoding Bytes))

# Any version
[Convert]::ToBase64String([IO.File]::ReadAllBytes('<filepath>'))