Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

azure
powershell
communitycreator

How to create an Azure resource group using PowerShell

Gutha Vamsi Krishna

In this shot, we will learn how to create an Azure resource group using PowerShell.

Azure Resouce Group is a logical group of resources that includes virtual machines, databases, web applications, and storage accounts.

This resource group stores metadata about the resources that it contains. The location of the metadata is specified in the “location” part of the resource.

How to create a resource group

Step 1

Install the latest version of Powershell. PowerShell 7.0.6 LTS, PowerShell 7.1.3, or higher is recommended by Microsoft.

Check the PowerShell version with the following command:

$PSVersionTable.PSVersion

This yields the information below.

Step 2

Next, set the Execution Policy:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

We can check the execution policy with the following command:

Get-ExecutionPolicy -List

This yields the description below.

Step 3

Install the Az module using this command:

Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

Step 4

Log in into the account with the command below.

It will provide a link to open it in the browser and enter the code provided.

Connect-AzAccount -UseDeviceAuthentication

After a successful login, it will print Account, SubscriptionName, TenantId, and Environment.

Step 5

Create a resource group with the following command:

New-AzResourceGroup -Name demoRG -Location "South Central US" -Tag @{Department="Sales"}

In the above command:

  • New-AzResourceGroup is a cmdlet used to create a resource group.
  • demoRG is the name of the resource group, which is passed as a parameter.
  • South Central US is the location where the metadata of the resource group is stored.
  • We can pass tags also, using ; as a separator.

After executing this command, it takes some time to create a resource group and returns the following output:

RELATED TAGS

azure
powershell
communitycreator
RELATED COURSES

View all Courses

Keep Exploring