我正在使用PowerShellCoreV6.0.2,并尝试将字节数组写入文件。这在常规的PowerShell中工作正常,但在PowerShell核心中失败。
$jsonstr=get content$inputfilename $jsonfile=从json$jsonstr转换 $bytes=[转换]:frombase64string($jsonfile.data) $outputfilename=“test.xlsx”; 添加内容-路径$outputfilename-值$bytes-编码字节 错误: 这是一个bug,还是因为二进制排序问题而不能再使用字节? $jsonstr = Get-Content $inputfilename $jsonfile = ConvertFrom-Json $jsonstr $bytes = [Convert]::FromBase64String($jsonfile.data) $outputfilename = "test.xlsx"; Add-Content -Path $outputfilename -Value $bytes -Encoding Byte 错误: 这是一个bug,还是因为二进制排序问题而不能再使用字节?
错误: 这是一个bug,还是因为二进制排序问题而不能再使用字节? $jsonstr = Get-Content $inputfilename $jsonfile = ConvertFrom-Json $jsonstr $bytes = [Convert]::FromBase64String($jsonfile.data) $outputfilename = "test.xlsx"; Add-Content -Path $outputfilename -Value $bytes -Encoding Byte 错误: 这是一个bug,还是因为二进制排序问题而不能再使用字节?
错误:
这是一个bug,还是因为二进制排序问题而不能再使用字节?
$jsonstr = Get-Content $inputfilename $jsonfile = ConvertFrom-Json $jsonstr $bytes = [Convert]::FromBase64String($jsonfile.data) $outputfilename = "test.xlsx"; Add-Content -Path $outputfilename -Value $bytes -Encoding Byte
根据这个博客 post ,在PowerShell核心上,需要将set content与asbytestream参数一起使用。
我已将脚本更改为以下内容:
$jsonstr = Get-Content $inputfilename $jsonfile = ConvertFrom-Json $jsonstr $bytes = [Convert]::FromBase64String($jsonfile.data) $outputfilename = "test.xlsx"; Set-Content -Path $outputfilename -Value $bytes -AsByteStream