New-AzResourceGroup

This Azure tutorial will discuss the syntax and usage of New-AzResourceGroup PowerShell Command with examples.

New-AzResourceGroup

This PowerShell command helps you Create an Azure resource group.

Syntax of New-AzResourceGroup

New-AzResourceGroup
   [-Name] <String>
   [-Location] <String>

Example – Create a new Resource Group

The below PowerShell command will create a new Resource Group named as “mynewresgroup123” on the location “West US”.

New-AzResourceGroup -Name "mynewresgroup123" -Location "West US"

But after executing the above PowerShell command, I got the below error.

The ‘New-AzResourceGroup’ command was found in the module ‘Az.Resources’, but the module could not be loaded. For more information, run ‘Import-Module Az.Resources’.

Check out the same error the below screen shot.

The 'New-AzResourceGroup' command was found in the module 'Az.Resources'

Now, to fix this error, I need to import the Az. Resources module. Below is the command I need to execute to do so.

Import-Module Az.Resources

Then I reran the below PowerShell command.

New-AzResourceGroup -Name "mynewresgroup123" -Location "West US"

It is asking to connect to the Azure Run Connect-AzAccount to login

The New-AzResourceGroup command was found

Now, you can run the below command to connect to Azure from PowerShell.

Connect-AzAccount

It will ask you to enter your username and password and then show your subscription details.

The New-AzResourceGroup command was found

Now rerun the below PowerShell command to create the resource group and the command has been executed successfully. Check out the below screenshot.

New-AzResourceGroup -Name "mynewresgroup123" -Location "West US"
the new azresourcegroup command was found

You may like the following Azure tutorial:

In this Azure tutorial, we discussed the syntax and usage of New-AzResourceGroup PowerShell Command with examples.