我通常使用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本身中的内置实用程序(使用较短的命令尽可能多地使用)?