How to get the azure resources from the resource group using PowerShell?

To get the available resources from the resource groups using PowerShell, we need to use the Get-AZResource command. Suppose we have the resource group name AnsibleTestRG and we need to retrieve the resources from the resource group, then we will use the below command.


Get-AzResource -ResourceGroupName AnsibleTestRG

To filter the output,


Get-AzResource -ResourceGroupName AnsibleTestRG | Select Name, ResourceType, Location


If there are multiple resource groups in the particular subscription, we can use the below commands to export the resources from the resource group to the CSV file.


$ErrorActionPreference = "Stop"
try {
    Set-AzContext -SubscriptionName 'Your Subscription Name'
    $rgs = Get-AzResourceGroup

    foreach ($rg in $rgs.ResourceGroupName) {
        Write-Output "Checking Resource Group: $rg"
        Get-AzResource -ResourceGroupName $rg | Select Name, ResourceGroupName, Type, Location | Export-Csv .\AzureResources.csv -Append -Force -NoTypeInformation
catch {
    Write-Host "$($_.Exception.Message)" -BackgroundColor DarkRed

Updated on: 12-Apr-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started