Home How do I replicate the Azure Resource Manager template uniquestring() function in Powershell?
Reply: 1

How do I replicate the Azure Resource Manager template uniquestring() function in Powershell?

FacticiusVir Published in 2018-01-10 14:58:29Z

I have an Azure-hosted service which is automatically deployed (in our build process) using ARM templates, with multiple instances of the service in different resource groups. Several of the resources require globally unique names, and to support this I'm using the uniquestring function (typically against the resource group ID) to generate part of those resource names. Names follow a templated pattern, e.g. Instance Name + Component Name + Unique String = "Example.WebAPI.abcd1234efgh5"

My problem arises later when using Powershell scripts to perform maintenance on those resources - I need the resource name, which means using the same template to generate the name from the instance, component and resource group IDs. However, there is no function in Powershell that returns the same value as the ARM uniquestring function for the same input.

As far as I'm aware, uniquestring is simply generating a hash of the input string and returning it as a 13-character representation; does anyone know the specifics of this hash process so it can be duplicated in Powershell, or if it has already been done?

I've looked at the answer for Can I call ARM template functions outside the JSON deployment template?, but this requires the use of output parameters in the initial ARM template and assumes the value is used immediately; whereas in my use case I need the resource name some weeks or months after the initial deploy.

4c74356b41 Reply to 2018-01-10 18:39:28Z

The function is not documented anywhere, but its deterministic, meaning you always get the same output if you give the same input, so nothing to worry about.

In case you need to identify the resource afterwards you can come up with a bunch of workaround, you can always get the output of the deployment using Get-AzureRmResourceGroupDeployment or you can tag the resource with something specific what you can infer dynamically or you could filter the resource out using things like time of creation and other indirect factors

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302159 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO