Created
November 3, 2022 12:13
-
-
Save l4rm4nd/6fb5e60abc84158f77e395b5ed712688 to your computer and use it in GitHub Desktop.
Convert EXE into Base64 String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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