0
votes

Trying to list all resource groups that contain a given tag value.

I was able to get a list of resources when hardcoding the value of the tag, but I am not successful when passing a variable containing the value.

getting the following error:

+ $resourceGroups = (Get-AzureRmResourceGroup -Tag @{ $Tag}).ResourceGr ...
+                                                         ~
Missing '=' operator after key in hash literal.
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEqualsInHashLiteral

not sure how to make the command evaluate the value of $Tag

2

2 Answers

0
votes

i think you should do something like this:

$tag = @{ "name" = "value" }
Get-AzureRmResourceGroup -Tag $Tag
0
votes

Just to elaborate, your parameter for tag is @{$tag} which means it interprets that you're specifying a hashtable instead of passing a hashtable. Your $tag variable will/should already be a hashtable so your command will look like what @4c74356b41 has specified

$resourceGroups = (Get-AzureRmResourceGroup -Tag $Tag).ResourceGroupName