PowerShell Base64 Encode String
$StringMsg = "This is my secret text"
# Gets the bytes of String
$StringBytes = [System.Text.Encoding]::Unicode.GetBytes($StringMsg)
# Encode string content to Base64 string
$EncodedString =[Convert]::ToBase64String($StringBytes)
Write-Host "Encode String: " $EncodedString
PowerShell Base64 Decode String
$EncodedString = "VABoAGkAcwAgAGkAcwAgAG0AeQAgAHMAZQBjAHIAZQB0ACAAdABlAHgAdAA="
$DecodedString = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($EncodedString))
Write-Output $DecodedString
Encoding a command using Base64
$StringMsg = "dir C:\"
$StringBytes = [System.Text.Encoding]::Unicode.GetBytes($StringMsg)
$EncodedString =[Convert]::ToBase64String($StringBytes)
Write-Host "Encode String: " $EncodedString
5/5 - (1 vote)