azure - Powershell 计算 azure CLI 结果
问题描述
我正在尝试实现我的输出,如果它是一行,它会被写在一个变量中
这就是我到目前为止所拥有的
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
推荐阅读
- statistics - 动态因果效应
- visual-studio - Visual Studio,与服务器的连接丢失错误
- gitlab - 如何排除gitlab代码质量扫描json文件中未包含的文件或文件夹以减少代码质量问题
- linux - 关于Linux中变量/环境变量范围的问题
- react-native - 如何在 useEffect 中使用 addListener
- github - 克隆私有存储库时如何解决错误
- jquery - Gatsby - 引导错误:util.js:68 Uncaught TypeError:无法读取未定义的属性“fn”
- java - 高效结合使用 logback、lombok 和 Spring Boot 2.4
- java - 仅调度时间窗口中的最新事件(每个聚合根)
- excel - 如何应用具有> 255 个字符的值的 Application.Match?