【问题标题】:Find Azure resource groups by tag name按标记名称查找 Azure 资源组
【发布时间】:2023-04-03 17:13:01
【问题描述】:

最近我在 Azure 自动化帐户中更新了 Azure Powershell 模块,似乎使用新版本的 AzureRm.Resources 模块处理资源标签和资源组更改的方式。 以前这是我列出具有 AutoShutdownSchedule 标记名称的资源组的方式

(Get-AzureRmResourceGroup | where {$_.Tags.Name -contains "AutoShutdownSchedule"}

现在根据https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-using-tags我必须使用:

Find-AzureRmResourceGroup -Tag @{Name="AutoShutDownSchedule"}

但这不会返回任何东西。但是 Find-AzureRmResourceGroup 正在工作:

    Find-AzureRmResourceGroup


id         : /subscriptions/xxxxx/resourceGroups/HaaS-CDH-Starter-Spotfire-1393
name       : xxxxx
location   : eastus2
tags       : @{AutoShutdownSchedule=18:00}
properties : @{provisioningState=Succeeded}

id         : /subscriptions/xxxxxx/resourceGroups/mnt-dev-us
name       : xxxx
location   : eastus2
tags       : @{AutoShutdownSchedule=18:00}
properties : @{provisioningState=Succeeded}

任何建议我做错了什么?

【问题讨论】:

  • 如果我的回答有助于解决您的问题,并且如果您感谢您的帮助,请将答案标记为可接受的答案。

标签: azure azure-powershell azure-resource-group


【解决方案1】:

您应该使用以下命令来获取名称为 AutoShutdownSchedule 的标签的资源组。

Find-AzureRmResourceGroup -Tag @{ AutoShutdownSchedule = $null }

Find-AzureRmResourceGroup cmdlet 的按标签名称查找资源组的示例可以从:

get-help Find-AzureRmResourceGroup -full
--------------------------  FindByTagName  --------------------------

Find-AzureRmResourceGroup -Tag @{ testtag = $null }

Finds all resource group with a tag with name 'testtag'.

注意:已验证使用AzureRm.Resources 模块版本:3.5.0

【讨论】:

    猜你喜欢
    • 2021-09-02
    • 1970-01-01
    • 2017-06-16
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多