我通常使用JQ来处理JSON。
PS C:\> gc pw.txt
{
"PowerShell": {
"is a task": {
"automation": [
{
"and": "configuration",
"management": [
{
"program": "from",
"microsoft": {
"consisting of": "a command-line",
"shell": {
"and": "the",
"associated": {
"scripting": {
"language.": "initially a windows",
"component": {
"only": "known as",
"windows": {
"powershell": "7.3.9-win-x64.msi",
"it was made": "open-source"
}
}
}
}
}
}
}
]
},
{
"the former": "is built on the .NET Framework",
"the latter on": ".NET (previously .NET Core)."
}
]
}
}
}
字符串
下面的方法在PowerShell中可以很好地从上面的JSON中获取值7.3.9-win-x64.msi
:
PS C:\> gc pw.txt | jq -r '.[] | .[] | .[] | .[].management | .[0].microsoft | .shell.associated.scripting.component.windows.powershell'
型
那么,现在我如何获得相同的值,而不使用JQ,而是使用PowerShell本身的内置实用程序(尽可能使用更短的命令)?
1条答案
按热度按时间uelo1irk1#
字符串