考虑下面的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}为什么下面没有(返回空白)
PS C:\Windows\system32> az group list | convertfrom-json | select-object name
name
----发布于 2020-04-28 19:33:12
这是一个关于ConvertFrom-Json和一个管道的Windows错误。
将命令分组为(),以便正确评估它们。
(az group list | ConvertFrom-Json) | Select-Object name它已经在PowerShell内核中修复了。
发布于 2020-04-28 19:46:39
除了Azure answer之外,你还可以使用来自@7cc's PowerShell的Azure Cmdlet,它将为你提供一个可以立即使用的PowerShell对象。这比使用az group list将来自Azure CLI的JSON输出转换为使用ConvertFrom-Json的System.Management.Automation.PSCustomObject更容易。
获取列Name中的所有资源组
Get-AzResourceGroup | Select-Object -Property @{Name = "Name"; Expression = { $_.ResourceGroupName } }或者只保留默认的ResourceGroupName列:
Get-AzResourceGroup | Select-Object -Property ResourceGroupNamehttps://stackoverflow.com/questions/61477911
复制相似问题