question

KalaimaniThirupathi-5306 avatar image
0 Votes"
KalaimaniThirupathi-5306 asked bharathn-msft edited

How to Get AzureRM Subscription tags Detail

Dear All, Can you someone help me to get the AzureRM subscription tags Detail using Powershell.

azure-migrateazure-dnsazure-policyazure-cyclecloud
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

tbgangav-MSFT avatar image
0 Votes"
tbgangav-MSFT answered KalaimaniThirupathi-5306 commented

Hi @KalaimaniThirupathi-5306,

You can get it by below commands.

 $SubscriptionId = (Get-AzureRmSubscription).Id
 (Get-AzurermTag -ResourceId "/subscriptions/$SubscriptionId").Properties.TagsProperty

For illustration, check below screenshots.

46591-image.png

46534-image.png


image.png (60.4 KiB)
image.png (43.5 KiB)
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Dear Krishna, I really appreciate your help in resolving this

1 Vote 1 ·

Dear,

getting the below error


46567-image.png


0 Votes 0 ·
image.png (64.2 KiB)
tbgangav-MSFT avatar image tbgangav-MSFT KalaimaniThirupathi-5306 ·

<<Continued>>

So final code using Az PowerShell could be as shown below only in case you have access to single subscription.

 $SubscriptionId = (Get-AzSubscription).Id
 (Get-AzTag -ResourceId "/subscriptions/$SubscriptionId").Properties.TagsProperty

In case you have access to multiple subscription then above code would fail as $SubscriptionId variable holds all the subscription ID's and hence it would fail in Get-AzTag line.

So Here is the final code using Az PowerShell even in case you have access to multiple subscriptions is shown below.

Below is the screenshot for illustration:

46580-image.png

1 Vote 1 ·
codeps1.txt (957 B)
image.png (94.5 KiB)

Thanks, Dear for your support, it's possible to get the Subscription name also like below

$OutputObjectTemp | Add-Member -membertype NoteProperty -name "SubscriptionId" -Value $SubscriptionId

$OutputObjectTemp | Add-Member -membertype NoteProperty -name "Subscription Name" -Value $Subscription
$OutputObjectTemp | Add-Member -membertype NoteProperty -name "TagKey" -Value $TagKey
$OutputObjectTemp | Add-Member -membertype NoteProperty -name "TagValue" -Value $TagValue

1 Vote 1 ·
tbgangav-MSFT avatar image tbgangav-MSFT KalaimaniThirupathi-5306 ·

Hi @KalaimaniThirupathi-5306,

Short answer: Use Az PowerShell but not AzureRM PowerShell.

Long answer: Firstly, screenshot that I have provided is from Azure Cloud Shell https://shell.azure.com and I see that your screenshot is from a local setup.

AFAIK reason it worked for me is because Get-AzureRMTag cmdlet (of legacy AzureRM PowerShell) is just an alias of actual cmdlet Get-AzTag (that's from Az PowerShell) as shown in below screenshot.

46607-image.png
Just FYI, starting in December 2018, the Az PowerShell module is in general release and is now the intended PowerShell module for interacting with Azure. So Az modules are latest recommended ones to use and AzureRM PowerShell modules are the older ones.

<<Response will be continued in the next comment as currently each comment can have max up to 1000 characters>>

0 Votes 0 ·
image.png (46.5 KiB)
tbgangav-MSFT avatar image tbgangav-MSFT KalaimaniThirupathi-5306 ·

<<Continued>>

As your error states, below screenshot confirms that -ResourceId parameter does NOT exist in AzureRM PowerShell cmdlet Get-AzureRMTag which is from the module AzureRM.Tags

46633-image.png

whereas, below screenshot confirms that -ResourceId parameter does exist in Az PowerShell cmdlet Get-AzTag which is from the module Az.Resources.

46657-image.png

0 Votes 0 ·
image.png (41.9 KiB)
image.png (50.4 KiB)
OnerZiyaBas-5108 avatar image
0 Votes"
OnerZiyaBas-5108 answered KalaimaniThirupathi-5306 commented

Check please...

get-azurermtag


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This is not working which I was already tested

0 Votes 0 ·