powershell convertfrom-json select-对象差异
powershell convertfrom-json select-object differences
考虑以下 json 负载(只是 "az group list" 中的示例片段):
[
{
"id": "/subscriptions/1f512sf9-112c-4a7a-a580-665afe4761f4/resourceGroups/dev-rg",
"location": "northeurope",
"managedBy": null,
"name": "dev-rg",
"properties": {
"provisioningState": "Succeeded"
},
"tags": {
"Application": "Integrations",
"Department": "Development Team",
"DeployedDate": "09/01/2020",
"Environment": "DEV",
"FundedBy": "INT",
"InterfaceId": "IFUS_007.1",
"Project": "INT"
},
"type": "Microsoft.Resources/resourceGroups"
}
]
谁能解释一下为什么下面的方法有效
PS C:\Windows\system32> az group list | convertfrom-json | select-object @{n='RSG';e={$_.name}}
RSG
---
{dev-rg}
为什么下面没有(returns空白)
PS C:\Windows\system32> az group list | convertfrom-json | select-object name
name
----
这是关于 ConvertFrom-Json 和管道的 Windows PowerShell 错误。
分组命令 ()
以便正确评估它们。
(az group list | ConvertFrom-Json) | Select-Object name
已在 PowerShell Core 中修复。
添加到 answer, you could also use Get-AzResourceGroup
Cmdlet from Azure PowerShell, which will give you a PowerShell object to work with immediately. This is easier than converting the JSON output from Azure CLI using az group list
to a System.Management.Automation.PSCustomObject
with ConvertFrom-Json
。
将所有资源组放在一列中 Name
:
Get-AzResourceGroup | Select-Object -Property @{Name = "Name"; Expression = { $_.ResourceGroupName } }
或者只保留默认的 ResourceGroupName
列:
Get-AzResourceGroup | Select-Object -Property ResourceGroupName
考虑以下 json 负载(只是 "az group list" 中的示例片段):
[
{
"id": "/subscriptions/1f512sf9-112c-4a7a-a580-665afe4761f4/resourceGroups/dev-rg",
"location": "northeurope",
"managedBy": null,
"name": "dev-rg",
"properties": {
"provisioningState": "Succeeded"
},
"tags": {
"Application": "Integrations",
"Department": "Development Team",
"DeployedDate": "09/01/2020",
"Environment": "DEV",
"FundedBy": "INT",
"InterfaceId": "IFUS_007.1",
"Project": "INT"
},
"type": "Microsoft.Resources/resourceGroups"
}
]
谁能解释一下为什么下面的方法有效
PS C:\Windows\system32> az group list | convertfrom-json | select-object @{n='RSG';e={$_.name}}
RSG
---
{dev-rg}
为什么下面没有(returns空白)
PS C:\Windows\system32> az group list | convertfrom-json | select-object name
name
----
这是关于 ConvertFrom-Json 和管道的 Windows PowerShell 错误。
分组命令 ()
以便正确评估它们。
(az group list | ConvertFrom-Json) | Select-Object name
已在 PowerShell Core 中修复。
添加到 Get-AzResourceGroup
Cmdlet from Azure PowerShell, which will give you a PowerShell object to work with immediately. This is easier than converting the JSON output from Azure CLI using az group list
to a System.Management.Automation.PSCustomObject
with ConvertFrom-Json
。
将所有资源组放在一列中 Name
:
Get-AzResourceGroup | Select-Object -Property @{Name = "Name"; Expression = { $_.ResourceGroupName } }
或者只保留默认的 ResourceGroupName
列:
Get-AzResourceGroup | Select-Object -Property ResourceGroupName