Powershell 计数 azure CLI 结果
Powershell count azure CLI result
我正在尝试实现我的输出,如果它是一行,它会被写入一个变量
这是我目前所拥有的
az group list --query '[].{name:name}' --output table
$filter = Read-Host -Prompt "Please filter to find the correct resource group"
az group list --query "[?contains(name, '$filter')].name" --output tsv
此代码的作用是您可以过滤所有资源组,然后您可以在 TSV 中查看输出
我想补充的是,它会检查它是否是唯一的一行,然后将该行写掉(如果是一行)
既然你已经在使用powershell,为什么不直接使用powershell呢?
$filter = Read-Host -Prompt "Please filter to find the correct resource group"
Get-AzResourceGroup | Where-Object { $_.ResourceGroupName -eq $filter }
感谢您帮助更改代码!
现在的最终结果是:
Connect-AzureRmAccount
(get-azurermresourcegroup).ResourceGroupName
$filter = Read-Host -Prompt "Please filter to find the correct resource group"
$RGName = get-azurermresourcegroup | Where-Object { $_.ResourceGroupName -match $filter }
$RGName.resourcegroupname
我正在尝试实现我的输出,如果它是一行,它会被写入一个变量
这是我目前所拥有的
az group list --query '[].{name:name}' --output table
$filter = Read-Host -Prompt "Please filter to find the correct resource group"
az group list --query "[?contains(name, '$filter')].name" --output tsv
此代码的作用是您可以过滤所有资源组,然后您可以在 TSV 中查看输出
我想补充的是,它会检查它是否是唯一的一行,然后将该行写掉(如果是一行)
既然你已经在使用powershell,为什么不直接使用powershell呢?
$filter = Read-Host -Prompt "Please filter to find the correct resource group"
Get-AzResourceGroup | Where-Object { $_.ResourceGroupName -eq $filter }
感谢您帮助更改代码! 现在的最终结果是:
Connect-AzureRmAccount
(get-azurermresourcegroup).ResourceGroupName
$filter = Read-Host -Prompt "Please filter to find the correct resource group"
$RGName = get-azurermresourcegroup | Where-Object { $_.ResourceGroupName -match $filter }
$RGName.resourcegroupname