小编Yum*_*umi的帖子

如何将 JSON(字符串数据)传递给 PowerShell?

我将以下内容作为参数传递给 powershell(w7 上的 v4):

-debugWrite -fileName SettingsFile -jsonContent { "c": "some setting", "d":  "unknown", "b": "some thing", "a": 1 }
Run Code Online (Sandbox Code Playgroud)

但是 PS 被 JSON 挂断了。我试过分隔 \double-quotes\ 并将 -jsonContent 之后的所有内容放在“单引号”中,但无济于事。

这是运行 PS 的 Windows 7 (PS4) 环境:

注意:“...”混淆指的是同一个目录。IOW,所有文件都位于同一目录中。

运行一个批处理文件,开始整个事情:

    "C:\...\script.bat" > "C:\...\script-output.txt" 2>&1
Run Code Online (Sandbox Code Playgroud)

这会运行script.bat并输出到script-output.txt. script.bat是一个长的 1-liner:

%WINDIR%\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\...\customscript.PS1" --% -fileName DropFileToCreate -jsonContent "{     "c":  "some setting",     "d":  "unknown",     "b":  "some thing",     "a":  1 }" -debugWrite
Run Code Online (Sandbox Code Playgroud)

传奇:

DropFileToCreate - 传递给 PS 脚本的文件名,用于在同一目录中创建文件。

-jsonContent- …

syntax powershell json batch-file quoting

2
推荐指数
1
解决办法
7315
查看次数

标签 统计

batch-file ×1

json ×1

powershell ×1

quoting ×1

syntax ×1