
PowerShell base64 encode PowerShell Base64 Encode Image Using ::Unicode.GetString() method converts from base64 string in PowerShell. It uses :: FromBase64String method which accepts base64 encodes string as an input parameter. In the above PowerShell script to decode the base64 string, $DecodedString = ::Unicode.GetString(::FromBase64String($EncodedString)) You can use FromBase64String() method to convert from base64 encoded string. Using the ToBase64String() method, it converts bytes to Base64 encoded string and prints it on the console. $StringBytes – variable contains Bytes for a given string using Unicode.GetBytes() $StringMsg – variable contains string content In the above PowerShell script to convert string to base64, Write-Host "Encode String: " $EncodedString $EncodedString =::ToBase64String($StringBytes)

$StringBytes = ::Unicode.GetBytes($StringMsg)

Let’s understand with an example of a base64 encoded string in PowerShell.įor example, if you want to base64 encode a string, use the below script $StringMsg = "PowerShell Base64 Encode Example"
BASE64 ENCODING ON WINDOWS HOW TO
Using the Set-Content cmdlet, it out base64 encoded file content to file at the specified location.Ĭool Tip: How to find large-size files in PowerShell! PowerShell Base64 Encode String $fileContentEncoded – contains base64 encode file content using ToBase64String() method which accepts $fileContentsInBytes parameter and convert file to base64. $fileContentInBytes – contains bytes about file content, get it using UTF8.GetBytes() method $FileContent – contains content of the file using the Get-Content cmdlet In the above PowerShell script to base64 encode file, Write-Host $FileName + ".b64" + "File Encoded Successfully!" $fileContentEncoded | Set-content ($fileName + ".b64") # Save Base64 Enconde file with extension. $fileContentEncoded = ::ToBase64String($fileContentInBytes) $fileContentInBytes = ::UTF8.GetBytes($FileContent) #Get the bytes of the file content with encode $FileName = "D:\Logs-FTP01\EncodeLogic.txt" PowerShell base64 encodes the file contents and saves the file to a location with a.

Use PowerShell script to take a file as input, and read the contents of the file using the Get-Content cmdlet. 5 Conclusion PowerShell Base64 Encode File Content
