How to create a new Azure resource group using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

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.

To create a new resource group, you need the location for the resource group. The below code will first connect to your Azure account, selects the Azure subscription, and then creates a new resource group.

Example

$ErrorActionPreference = "Stop"
Connect-AzAccount
Set-AzContext -SubscriptionName 'Enter your subscription name here'
New-AzResourceGroup -Name 'TestRG' -Location 'Central US' -Tag @{'RG'='APP'}

Output

ResourceGroupName : TestRG
Location          : centralus
ProvisioningState : Succeeded
Tags              :
                    Name  Value
                    ====  =====
                    RG    APP

ResourceId        : /subscriptions/8ac5a3e4-390b-9034-8ad5-3585aseesasac/resourceGroups/TestRG

The above command will create the Azure Resource group at the Central US location with the associated tag ‘RG’ and its value ‘APP’

raja
Published on 12-Apr-2021 11:13:54
Advertisements