网上找的代码可以将二进制程序生成base64的字符串并存储在b64.txt中,执行了代码没有报错但是也不见生成b64.txt,代码如下
function Convert-BinaryToString {
[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.';
}
$Base64String | set-content ("b64.txt")
}