Convert to Base64 encoded string using PowerShell one-liner

PowerShell doesn’t provide built-in cmdlets for conversion from string to Base64 encoded string. This task can be done by combination of .NET methods Encoding.GetBytes and Convert.ToBase64String. PowerShell one-liner is then simple:


We can even omit System namespace to simplify one-liner:


Output is Base64 encoded string:


More about using .NET in PowerShell can be found in documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *