February 26, 2020

PowerShell :: Convert text file to Base64

PowerShell ISE logo
(Last Updated On: 20th September 2016)


So this script will read the text from a plain text file and then encode it as Base64. It is useful for Base64 encoding PowerShell scripts if you are looking to pass the script as an encoded command line argument. You will need to set the $inputFilePath and $outputFilePath and then execute. You could enter the text into the variable but as you start to get into bother with special characters that you just won’t have to worry about if you read from a file.

$inputFilePath = "C:\PowerShellScript.ps1"
$outputFilePath = "C:\Output.txt"

$powerShellScript = [IO.File]::ReadAllText($inputFilePath)
$bytes = [System.Text.Encoding]::Unicode.GetBytes($powerShellScript)
[Convert]::ToBase64String($bytes) > $outputFilePath
Previous «
Next »

Simon is a sysadmin for a global financial organisation and specialises in Windows, security and automation.


  1. Pingback: an intro to macro malware – Synack
  2. Pingback: Using PowerSploit to inject MSFVenom shellcode – Synack

Leave a Reply

Subscribe to SYNACK via Email

%d bloggers like this: