tester81
tester81

Reputation: 595

azure powershell Get-Azurermresource, How to get unique ID of a specific resource

I am preparing a script, and I need the get a specific ID of a resources, I tried to use get-azurermresource but it gives me only value like - ResourceId. For me this is not an unique ID of this resorce because when we remove resource and re-create it with the same name mentioned ResourceId will be the same. I am able to get this unique ID in case of Azure VM, using cmd-let --> GetAzVM, I got --> VmId : 604f7764-7ffe-4be0-b313-81ca9deda5ad. But what about the rest of the resources? is there any method to get mentioned "unique ID" for other resources?

Upvotes: 0

Views: 966

Answers (2)

Ken W - Zero Networks
Ken W - Zero Networks

Reputation: 3804

To get a truly unique ID you will need to incorporate your subscriptionID along with ResourceGroupName and Provider. That is how we do it on our backend. For example, a VM disk's ResourceID for the service fabric would look something like this (get-azurermresource will show this):

/subscriptions/a4cd20a0-af7c-4278-8875-dc54076450f8/resourceGroups/MY-ResourceGroup/providers/Microsoft.Compute/disks/my_dev_disk00455

Upvotes: 1

MikeWo
MikeWo

Reputation: 10975

As far as the Azure platform is concerned, the ResourceID is the uniqueID. It contains the subscriptionId, and the name of the resource. While you are correct, if you delete a resource and create another of the same name in the same subscription it will have the same ResourceID, it still uniquely identifies that created resource at that time.

The VmId is an outlier that is used to uniquely identify not only that VM, but that VM across other VM deployments that might be created, deleted, and recreated. This is useful for things like licensing because it's set at the SMBIOS level and can't be changed. Most, if not all, other resource types don't have this type of identifier.

If you want something that will identify a resource across different deployment instances, that may be harder to do with information direct from the platform. You might have to handle that on your own. Tags might be an option depending on what you are trying to accomplish.

Upvotes: 1

Related Questions