【问题标题】:Add-Content bytes fails with PowerShell CorePowerShell Core 添加内容字节失败
【发布时间】:2018-07-03 13:26:48
【问题描述】:

我正在使用 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?

【问题讨论】:

    标签: powershell powershell-core


    【解决方案1】:

    根据此博客post,在 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
    

    【讨论】:

      猜你喜欢
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-12
      • 2017-11-30
      • 2012-10-16
      • 2019-01-20
      • 1970-01-01
      相关资源
      最近更新 更多