In the previous post, we showed how to create and remove a Resource Group using the Azure portal. If you have not read it yet, use this link. Today we will talk about how to work with Resource Groups using PowerShell and Azure CLI.
Creating a Resource Group using PowerShell
To connect to Azure using PowerShell, you need to install the Azure module or access it directly in the Azure portal. To run the Azure module in local PowerShell, you need to be using version 5.1 of this software and also have .NET Framework 4.7.2 or later. More information can be found at this link.
To find your PowerShell version, run the command “$PSVersionTable.PSVersion”, as shown below:

You can install this module by opening PowerShell with elevated privileges and running the command “Install-Module -Name Az -AllowClobber”

Open PowerShell and connect to your Azure subscription with the command “Connect-AzAccount”.

Enter your Azure account credentials on the screen below.


Now let’s create a Resource Group using PowerShell. As an example, I ran the command “New-AzResourceGroup -Name “Lab2-ps” -Location “Central US” -Tag @{Department=”Marketing”}”
Syntax: New-AzureRmResourceGroup -Name resource group name -Location “Azure group location” -Tag @{tag name or type}
With the Resource Group created, you can view it in the Azure groups panel.

Creating a Resource Group using Azure CLI
Azure CLI is a shell for creating and running automated tasks in Azure. You can run it directly in the portal or download and install it on your device. You can use Azure CLI on Ubuntu 16, Windows 10, and macOS. For more information, use this link.
With Azure CLI installed, open Command Prompt and connect to your subscription using the command “az login”.

Enter the credentials for your Azure subscription.

Now let’s create a Resource Group using Azure CLI. As an example, I ran the command “az group create –location westus -n “Lab2-azcli” –tags vendas
Syntax: az group create -Location “Azure group location” -n resource group name –tags tag name or type

For more options for the Resource Group creation command in Azure CLI, use this link.
With the Resource Group created, you can view it in the Azure groups panel.

Removing Resource Groups using PowerShell and Azure CLI
To remove the Resource Group using PowerShell, run the command “Remove-AzResourceGroup -Name Lab2-ps” and confirm.

Azure CLI
To remove the Resource Group using Azure CLI, run the command “az group delete -n lab2-azcli” and confirm.

Summary
In today’s post, we showed how to create and delete Resource Groups in Azure using the PowerShell and Azure CLI command-line tools.
In the next post, we will talk about how to prevent accidental deletion of resources in Azure using Resource Lock, how to control access to resources using Access Control (IAM), and policy options with Azure Policy.
Did you like the post? Please like and share.
Best regards,
Ulysses Neves
