Microsoft Azure – Create Resource Group with Tags using PowerShell

In this article, I am going to show you how to create resource groups with tags using PowerShell in Microsoft Azure from Azure Cloud Shell in simple easy steps. Let’s get started.

Prerequisite: Contributor Access on Subscription to create a resource group in Azure Subscription.

Steps to Create a Resource Group

Step 1: Log in to Azure Portal

Step 2: Access the Cloud Shell from the Portal

Step 3: Switch to PowerShell Console

Step 4: Create a PowerShell file named createRGwithTags.ps1

$ touch createRGwithTags.ps1

Step 5: Open a file to code in createRGwithTags.ps1

$ code createRGwithTags.ps1

 

Copy and paste the below PowerShell code in the createRGwithTags.ps1 file. Modify the Parameter according to your needs to deploy a resource group.

# Parameteres
$RGroupName = "<Add resource group name"
$RGroupLocation = "<Add location name>"
## Add/Modify Tags of your Choice
$ResourceGroupTags = @{
"Environment" = "TEST"; 
"SystemCriticality" = "LOW";
"BusinessOwner" = "w3wiki";
"BusinessOwnerEmail" = "gfg@gfg.com";
"CostCenter" = "XYZ";
"SupportTeam" = "XYZ"
}


# Create Resource Group
New-AzResourceGroup \
    -Name $RGroupName \
    -Location $RGroupLocation \
    -Tag $ResourceGroupTags

Step 6: After making the changes in the script. Run the createRGwithTags.ps1 file

./createRGwithTags.ps1