You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Set-AzStorageFileContent保存文件出现异常换行问题求助

问题原因与解决方法

原因

PowerShell会自动将本地JSON文件的内容解析为PowerShell对象(此处是数组),而Set-AzStorageFileContent默认会把这个对象序列化为JSON字符串后上传,导致原始JSON内容被二次序列化,最终出现外层双引号、转义后的换行符\r\n这类格式异常。

解决方法

要保留原始文件的换行和格式,需要强制命令以原始内容或二进制方式上传,避免对象解析与二次序列化:

  • 方法一:读取原始字符串内容后上传
$content = Get-Content -Path C:\Temp\A.json -Raw
Set-AzStorageFileContent -Context $SA.Context -ShareName $ShareName -Value $content -Path 'A.json' -Force
  • 方法二:以二进制编码模式直接上传文件
Set-AzStorageFileContent -Context $SA.Context -ShareName $ShareName -Source C:\Temp\A.json -Path 'A.json' -Encoding Byte -Force

内容的提问来源于stack exchange,提问作者Rudhan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 08:12:33