Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-AzureRMResource by tag when tag value is "unknown" displays all resources #6765

Closed
sluhn-woodrum opened this issue Jul 25, 2018 · 4 comments
Assignees
Labels
ARM Azure PS Team Service Attention This issue is responsible by Azure service team.

Comments

@sluhn-woodrum
Copy link

Description

From this article: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-using-tags

When performing this command, I receive an output of all resources in the resource group $RG.

(Get-AzureRmResource -ResourceGroupName $RG -Tag @{cost_center="unknown"}).Name

In this case, all but a few resources have a defined cost_center, and I have a subscription policy that places an "unknown" value for the tag "cost_center". This is using Azure Powershell 6.5. Previously, I used the command Find-AzureRmResource -TagName "cost_center" -TagValue "unknown" which pulled this list of resources that needed to be updated.

If I change the command (and update one of the resources to a cost_center of abc123, the PS command just returns the 1 resource. Additionally, the Azure portal properly displays the "unknown" cost center resources appropriately, so I believe this to be a bug in Azure PS 6.5

Script/Steps for Reproduction

(Get-AzureRmResource -ResourceGroupName $RG -Tag @{cost_center="unknown"}).Name

Module Version

Get-Module -Name AzureRM -ListAvailable

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version Name ExportedCommands


Script 6.5.0 AzureRM
Script 5.7.0 AzureRM

Environment Data

$PSVersionTable

Name Value


PSVersion 5.1.17134.137
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.137
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Debug Output


@sluhn-woodrum
Copy link
Author

Update: The following syntax also has the same issue, whereby the value of "unknown" displays all resources in the RG.

Get-AzureRmResource -ResourceGroupName $RG -Tagname "cost_center" -TagValue "unknown" | ft

@cormacpayne
Copy link
Member

@Woodrum good catch! I'm able to reproduce this on my machine. It looks like our logic is incorrect when handling the scenario where both a name and value are provided, but is correct when only one of the two is provided. Let me open a PR to fix this and hopefully get it into our next release.

In the meantime, you can workaround this issue with the following commands:

$name = "cost_center"
$value = "unknown"
Get-AzureRmResource -ResourceGroupName $RG | where { $_.Tags[$name] -eq $value } | ft

@sluhn-woodrum
Copy link
Author

@cormacpayne - thanks a lot... the workaround is great. To be clear, the command did work when the value I passed was anything but "unknown". So passing both a name and value works, but if the value is "unknown" it displayed all resources.

@cormacpayne
Copy link
Member

This has been fixed and will be available in the 6.6.0 release of AzureRM

@bsiegel bsiegel added the Service Attention This issue is responsible by Azure service team. label Sep 26, 2018
@mozehgir mozehgir added the ARM label Aug 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARM Azure PS Team Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

4 participants