1

我正在使用 PowerShell Core v6.0.2,并尝试将字节数组写入文件。这在常规 PowerShell 中运行良好,但在 PowerShell Core 中失败

$jsonstr = Get-Content $inputfilename
$jsonfile = ConvertFrom-Json $jsonstr
$bytes = [Convert]::FromBase64String($jsonfile.data)

$outputfilename = "test.xlsx";

Add-Content -Path $outputfilename -Value $bytes -Encoding Byte

错误:

在此处输入图像描述

这是一个错误还是由于二进制排序问题而不能再使用 Byte ?

4

1 回答 1

1

根据这篇博文,在 PowerShell Core 上,您需要使用带有 AsByteStream 参数的 Set-Content

我已将脚本更改为以下内容:

$jsonstr = Get-Content $inputfilename
$jsonfile = ConvertFrom-Json $jsonstr
$bytes = [Convert]::FromBase64String($jsonfile.data)

$outputfilename = "test.xlsx";
Set-Content -Path $outputfilename -Value $bytes -AsByteStream
于 2018-07-24T08:55:02.017 回答