Posts Custom PowerShell API for Azure Naming Policy
Post
Cancel

Custom PowerShell API for Azure Naming Policy

Azure PowerShell API for Azure Naming Policy - AzureIs.Fun

To continue our PowerShell API series, we have another example of a highly useful API that you can integrate into your environment.

Choosing names for Azure resources can be a challenging task. With so many options and requirements, it can be difficult to know where to start. Fortunately, there are resources available to simplify this process.

One such resource is the Cloud Adoption Framework page with abbreviations for Azure Resources Abbreviation examples for Azure resources.

Of course, manually checking that page will not save us any time. Therefore, we will create a script to extract the information and save it inside an object that we can use.

Use PowerShell to collect Resource Name Abbreviations data from HTML page

Here is that script:

Lately, I have experienced compatibility issues with existing HTML parsing modules and cmdlets, so I have decided to use regex instead. Although this is not the cleanest method, you can check other options such as the PowerHTML module or use ParsedHTML property of Invoke-WebRequest on Windows PowerShell v5.

Now we can use this data to display the abbreviations for our resources.

Get Name Abbreviation for Azure Resource Type

Here is the first function that we can use to quickly return the abbreviation for a resource type or namespace:

Get Name Abbreviation for existing Azure Resource

Here is another function that we can use to check the resource type and abbreviation for existing resources:

Get Naming Convention for Resource Type

Here is another version of this function that will give you the entire resource name based on a predefined naming policy:

You can easily extend this script to accept parameters such as subscription name, environment, location, abbreviations, etc., and to use an existing file as input so that you don’t need to keep your policy defined within the script.

Create your own PowerShell API

You can use these as individual scripts or combine them into one Azure Function API that is always available, saving you time when creating resources.

To speed up the process, you can also schedule the first script to run separately once a day and save the output in a file that the other functions can easily read.

Check out my previous article to learn how to Create Your Own PowerShell APIs for Azure Governance with Azure Function App and how that can be useful for your daily Azure Administrator tasks.

Another way of having Azure Resource Naming Policy quickly available to you is to use Azure Dashboards for Azure Governance.


I hope this article was helpful. Keep clouding around!

Vukasin Terzic

This post is licensed under CC BY 4.0