How to Create a New Azure Resource Group using PowerShell?

Table of Contents

Azure Resource Group is a container that stores the resources like Virtual Machines, Storage, IP addresses, etc. To create a new Azure Resource group, we need to use the New-AzResourceGroup command.

To use this cmdlet, you first need to connect to the Azure account, and then if you want to create a resource group for the particular subscription you need to select that subscription.

Connect to Microsoft Azure PowerShell

First, you need connect to Microsoft Azure PowerShell, there’re two ways to run PowerShell commands in Microsoft Azure:

Method 1: From Azure PowerShell modules installed in a computer.

How to Create a New Azure Resource Group using PowerShell?

Method 2: From Azure Cloud Shell using browsers.

How to Create a New Azure Resource Group using PowerShell?

Create a resource group using PowerShell

1. To create a new resource group, you need the location for the resource group. Find the list of Azure Regions and Locations.

Get-AzLocation | FT

2. The below command will create the Azure Resource group at the East US location with the associated tag ‘RG’ and its value ‘WEB’.

New-AzResourceGroup -Name 'TestRG' -Location 'eastus' -Tag @{'RG'='WEB'}
New-AzResourceGroup -Name 'TestRG' -Location 'eastus' -Tag @{'RG'='WEB'}

ResourceGroupName : TestRG
Location          : eastus
ProvisioningState : Succeeded
Tags              :
                    Name  Value
                    ====  =====
                    RG    WEB

ResourceId        : /subscriptions/089d4ee9-0b8d-4bac-ab78-c120f115e79e/resourceGroups/TestRG

How do you know it works ?

Run Get-AzResouceGroup to show the list of resource groups in the subscription.

Get-AzResourceGroup | FT

ResourceGroupName          Location ProvisioningState Tags TagsTable
-----------------          -------- ----------------- ---- ---------
cloud-shell-storage-eastus eastus   Succeeded
TestRG                     eastus   Succeeded         {RG} ...

Or you can find the created group in the Azure portal.

How to Create a New Azure Resource Group using PowerShell?

Leave a Comment

Required fields are marked *