Creating Azure Resource Group With PowerShell

Introduction

This article demonstrates how to create an Azure resource group with the help of Azure PowerShell. Resource groups provide a way to monitor, control access, provision and manage billing for collections of assets, which are required to run an application or be used by a client or company department. Azure Resource Manager (ARM) is the technology that works at the back-end, so that you can administer assets , using these logical containers. The resource group can include all the resources for the solution or only those resources, which you want to manage as a group. You decide how you want to allocate the resources to resource groups based on what makes the most sense for your organization. Generally, add the resources that share the same lifecycle to the same resource group, so you can easily deploy, update and delete them as a group.

Pre-requisite

Before we dive into creating a resource group in Azure with the help of PowerShell, we need to install Azure PowerShell on your machine. Azure PowerShell can be installed on it from the PowerShell Gallery, using the Web Platform Installer (WebPI) or using the MSI file available from GitHub. You can do this by using “Microsoft Web Platform Installer” by searching on your computer. Open “Microsoft Web Platform Installer” with the administrative privileges and search for “Microsoft Azure PowerShell”. Find the appropriate entry, click on Add and then click Install.


If you have installed Azure PowerShell in the past but have not updated it recently, consider installing the latest version.

Get-Module -ListAvailable -Name AzureRm.Resources | Select Version

Login to Azure account

Before working on Azure resource group, you need to log in to your Azure account. To log in to your Azure account, use the Login-AzureRmAccount cmdlet.


Login-AzureRmAccount

The cmdlet prompts you for the login credentials for your Azure account. After logging in, it downloads your account settings, so they are available to Azure PowerShell.


If you have more than one subscription, you can switch to a different subscription. First, let's see all the subscriptions for your account.

Get-AzureRmSubscription

The cmdlet given above returns the list of the available subscriptions associated with your account.


To switch to a particular subscription, use Set-AzureRmContext cmdlet with either SubscriptionId or SubscriptionName parameter.

Set-AzureRmContext –SubscriptionId {SubscriptionId}

OR

Set-AzureRmContext -SubscriptionName "{SubscriptionName}"

Once the appropriate subscription is set, you will see currently set subscription details.


Create a Resource Group

Before deploying any resources to your subscription, you must create a resource group, which will contain the resources, which you need.

To create a resource group, use the New-AzureRmResourceGroup cmdlet. The command uses the name parameter to specify a name for the resource group and the location parameter to specify its location.

New-AzureRmResourceGroup -Name NewResourceGroup1 -Location "East US"

Once resource group is successfully created, you will get new resource group details, as shown below.


Get Target Resource Group

At a later point of time, you can retrieve your resource group by logging in to your Azure account, selecting the appropriate subscription, if you have more than one subscription, and then using Get-AzureRmResourceGroup cmdlet with name parameter.

Get-AzureRmResourceGroup -Name NewResourceGroup1

To get all the resource groups within your subscription, you can use above cmdlet without specifying Name parameter.

Get-AzureRmResourceGroup

Summary

In this article, I discussed how we can create a new Azure resource group with the help of Azure PowerShell. We also discussed about how to install Azure PowerShell, start Azure PowerShell session to execute the commands to Azure, select an appropriate subscription, if you have more than one subscription and then create a new Resource Group, find an existing Resource Group and list all the resource groups within the selected subscription.

Up Next
    Ebook Download
    View all
    Learn
    View all