Create Multiple Azure Resource Groups With PowerShell

In this blog post, I will show you how to create multiple Azure Resource Groups using Azure PowerShell.

A few weeks ago, I showed you how to use Azure PowerShell, and today I will use it to create RGs.

The great thing about Azure PowerShell is that we can use a CSV file to create resources.

CSV

rgs
RG-NAME-01
RG-NAME-02
 

Below is the CSV file that I have with the resource groups I need to create.

I have only two in the example, but you can use it with 200.

Set Subscription

After saving the CSV, I will connect to Azure using PowerShell and set the subscription.

Note: If you have only one subscription, you can skip this part.

To get a list of all your subscription, use the following command.

get-AzSubscription

To set the subscription, I will use the command below.

Set-AzContext -SubscriptionId "NAME of ID"

Script

My final script looks like code below. It takes the CSV, creates the RGs and set the location \ region.

Import-CSv rg.csv   |foreach{New-AzResourceGroup -name $_.rgs -location "eastus"}

To check that the RGs are alive, I will run the cmdlet below.

get-AzResourceGroup | ft

Posted

in

,

by