TechExplorer
TechExplorer

Reputation: 3

Azure resources

I have two questions with respect to Azure cloud -

  1. Is there a way to get all the resourceIds along with tags for a subscription in azure?
  2. Is there a way to get all the resourceIds in a subscription based on tag value?

Thanks in advance

Upvotes: 0

Views: 319

Answers (2)

Harald F.
Harald F.

Reputation: 4763

Depending if you're using the new AZ Modules or the old AzureRM modules - you have a couple of options.

The new AZ Module is recommended for operating towards Azure from Powershell (cross platform and newer Powershell versions). For more information look here: https://learn.microsoft.com/en-us/powershell/module/az.resources/get-azresource

Multiple options to find resources, and getting back tags, resourceId (and other properties) - and allowing you to filter based on a tag; either by a hashtable of tags. This would be better if you want to filter and fetch only certain resources (instead of getting all resources from Azure and filter afterwards). Example getting resources by tag:

# Using hashtable 
$resources = Get-AzResource -tag @{"costCenter"="201011";} 
# No filter - get all resource s
$resources = Get-AzResource;
# If using AzureRM 
$resources = Get-AzureRMResource -tag @{"costCenter"="201011";} 

or by using -tagName -tagValue

# Using -TagName & TagValue 
$resources = Get-AzResource -TagName "costCenter" -TagValue "201111"; 
# If using AzureRM 
$resources = Get-AzureRMResource -TagName "costCenter" -TagValue "201111"; 

You then have all the resources in your $resources variable - so you can easily select the ResourceId and/or tags (and other properties):

$resources|Select ResourceId

If you want to discover what properties are on an object in resources - experiment with this:

$resources[0]|Get-Member 

Upvotes: 0

VIJAY RAAVI
VIJAY RAAVI

Reputation: 406

To Get ResourceId's with tags use below cmdlet

Get-AzResource|select ResourceId,Tags

To Get the ResourceId's based on the tag value use below cmdlet

Get-AzResource -TagValue "<Replace tag value here>" |select ResourceId

Upvotes: 0

Related Questions