Skip to content

Instantly share code, notes, and snippets.

@l4rm4nd
Created November 3, 2022 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l4rm4nd/6fb5e60abc84158f77e395b5ed712688 to your computer and use it in GitHub Desktop.
Save l4rm4nd/6fb5e60abc84158f77e395b5ed712688 to your computer and use it in GitHub Desktop.
Convert EXE into Base64 String
function Convert-BinaryToBase64String {
[CmdletBinding()] param (
[string] $FilePath
)
try {
$ByteArray = [System.IO.File]::ReadAllBytes($FilePath);
}
catch {
throw "Failed to read file. Ensure that you have permission to the file, and that the file path is correct.";
}
if ($ByteArray) {
$Base64String = [System.Convert]::ToBase64String($ByteArray);
}
else {
throw '$ByteArray is $null.';
}
Write-Output -InputObject $Base64String;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment