Base64 with PowerShell

All too often I find myself on a Windows system and need to either encode or decode base64. Rather than using an online service, installing a program, or going to a *nix based system, I took to PowerShell. In PowerShell, we can use .NET to accomplish this.


$Text2Encode = ‘PowerShell is Great!’
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text2Encode)
$EncodedText =[Convert]::ToBase64String($Bytes)

The result is this base64 encoded text:



$DecodedText = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($Data2Decode))