How to get Azure resources from a resource group using PowerShell
Overview
The 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.
Let’s have a look at the following steps to get Azure resources from the 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 to 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
Get Azure resources from a resource group using the following command:
Get-AzResource -ResourceGroupName demo
- The
Get-AzResourceis the cmdlet provided by theAzmodule to get a list of Azure resources in a resource group. - This cmdlet takes
ResourceGroupNameas a parameter, where we pass the resource group name for which we want to list all the resources under it.