Get-AzResource

In this Azure PowerShell article, we will discuss the syntax and usage of the Get-AzResource Azure PowerShell cmdlet with examples.

Get-AzResource

Get-AzResource is an excellent Azure PowerShell cmdlet that can help you to get a list of all the Azure resources.

Syntax of Get-AzResource

Below is the syntax of the Get-AzResource Azure PowerShell cmdlet.

Get-AzResource
Get-AzResource
 [-Name <String>]
 [-ResourceType <String>]
 [<CommonParameters>]

Let’s discuss some examples

Example-1:

You can execute the below Azure PowerShell cmdlet to get the list of resources under your current subscription.

Get-AzResource

Once, I have executed the above Azure PowerShell cmdlet, I got the below output

PS C:\WINDOWS\system32> Get-AzResource


Name              : csg1003bffda6faf387
ResourceGroupName : cloud-shell-storage-centralindia
ResourceType      : Microsoft.Storage/storageAccounts
Location          : centralindia
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /cloud-shell-storage-centralindia/providers/Microsoft.Storage/stor
                    ageAccounts/csg1003bffda6faf387
Tags              : 
                    Name               Value            
                    =================  =================
                    ms-resource-usage  azure-cloud-shell
                    

Name              : Failure Anomalies - NewPowerShellAzureFNApp202105201249
ResourceGroupName : MyNewResGrp
ResourceType      : microsoft.alertsmanagement/smartDetectorAlertRules
Location          : global
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /MyNewResGrp/providers/microsoft.alertsmanagement/smartDetectorAle
                    rtRules/Failure Anomalies - NewPowerShellAzureFNApp202105201249
Tags              : 

Name              : Failure Anomalies - groupazureapp
ResourceGroupName : GroupAzure
ResourceType      : microsoft.alertsmanagement/smartDetectorAlertRules
Location          : global
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /GroupAzure/providers/microsoft.alertsmanagement/smartDetectorAler
                    tRules/Failure Anomalies - groupazureapp
Tags              : 

Name              : Failure Anomalies - TsinfoNew
ResourceGroupName : TsinfoNew_group
ResourceType      : microsoft.alertsmanagement/smartDetectorAlertRules
Location          : global
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /TsinfoNew_group/providers/microsoft.alertsmanagement/smartDetecto
                    rAlertRules/Failure Anomalies - TsinfoNew
Tags              : 

Name              : demoggh
ResourceGroupName : DEMORG2
ResourceType      : Microsoft.Storage/storageAccounts
Location          : eastus
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG2/providers/Microsoft.Storage/storageAccounts/demoggh
Tags              : 

Name              : TsInfo
ResourceGroupName : DEMORG1
ResourceType      : Microsoft.ServiceBus/namespaces
Location          : northeurope
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG1/providers/Microsoft.ServiceBus/namespaces/TsInfo
Tags              : 

Name              : insight2061
ResourceGroupName : DEMORG1
ResourceType      : Microsoft.Insights/components
Location          : northeurope
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG1/providers/Microsoft.Insights/components/insight2061
Tags              : 

Name              : DefaultWorkspace-1cdf4300-dee5-4518-8c8c-feaa72a5chu1-lb0fld0h
ResourceGroupName : DEMORG1
ResourceType      : Microsoft.OperationalInsights/workspaces
Location          : eastus
ResourceId        : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups
                    /DEMORG1/providers/Microsoft.OperationalInsights/workspaces/Defaul
                    tWorkspace-1cdf4300-dee5-4518-8c8c-feaa72a5chu1-lb0fld0h
Tags              : 

Name              : tsinfospringapp
ResourceGroupName : DEMORG1
ResourceType      : Microsoft.AppPlatform/Spring
Location          : eastus
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG1/providers/Microsoft.AppPlatform/Spring/tsinfospringapp
Tags              : 

Name              : Application Insights Smart Detection
ResourceGroupName : DEMORG1
ResourceType      : microsoft.insights/actiongroups
Location          : global
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG1/providers/microsoft.insights/actiongroups/Application 
                    Insights Smart Detection
Tags              : 

Name              : Failure Anomalies - insight2061
ResourceGroupName : DEMORG1
ResourceType      : microsoft.alertsmanagement/smartDetectorAlertRules
Location          : global
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG1/providers/microsoft.alertsmanagement/smartDetectorAlertRu
                    les/Failure Anomalies - insight2061
Tags              : 

Name              : ebautomation2d63gnquao4hu
ResourceGroupName : TsInfoRG-deployment
ResourceType      : Microsoft.Automation/automationAccounts
Location          : eastus
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /TsInfoRG-deployment/providers/Microsoft.Automation/automationAcco
                    unts/ebautomation2d63gnquao4hu
Tags              : 

Name              : ebautomation2d63gnquao4hu/inputValidationRunbook
ResourceGroupName : TsInfoRG-deployment
ResourceType      : Microsoft.Automation/automationAccounts/runbooks
Location          : eastus
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /TsInfoRG-deployment/providers/Microsoft.Automation/automationAcco
                    unts/ebautomation2d63gnquao4hu/runbooks/inputValidationRunbook
Tags              : 

Name              : TsInfoScaling
ResourceGroupName : DEMORG1
ResourceType      : Microsoft.DesktopVirtualization/scalingplans
Location          : eastus
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG1/providers/Microsoft.DesktopVirtualization/scalingplans/Ts
                    InfoScaling
Tags              : 

Name              : TsinfoRT
ResourceGroupName : DEMORG1
ResourceType      : Microsoft.Network/routeTables
Location          : northeurope
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG1/providers/Microsoft.Network/routeTables/TsinfoRT
Tags              : 

Name              : tsinfops
ResourceGroupName : DEMORG1
ResourceType      : Microsoft.DBforPostgreSQL/flexibleServers
Location          : eastus
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG1/providers/Microsoft.DBforPostgreSQL/flexibleServers/tsinf
                    ops
Tags              : 

Name              : demorg2913f
ResourceGroupName : DEMORG2
ResourceType      : Microsoft.Storage/storageAccounts
Location          : eastus
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG2/providers/Microsoft.Storage/storageAccounts/demorg2913f
Tags              : 

Name              : ASP-DEMORG2-861c
ResourceGroupName : DEMORG2
ResourceType      : Microsoft.Web/serverFarms
Location          : eastus
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG2/providers/Microsoft.Web/serverFarms/ASP-DEMORG2-861c
Tags              : 

If you want the same output in a tabular structure, you can run the below Azure PowerShell cmdlet.

Get-AzResource | Format-Table

After executing the above command, I got the below output

PS C:\WINDOWS\system32> Get-AzResource | Format-Table

Name                                                           ResourceGroupName      
----                                                           -----------------      
csg1003bffda6faf387                                            cloud-shell-storage-...
Failure Anomalies - NewPowerShellAzureFNApp202105201249        MyNewResGrp            
Failure Anomalies - groupazureapp                              GroupAzure             
Failure Anomalies - TsinfoNew                                  TsinfoNew_group        
demoggh                                                        DEMORG2                
TsInfo                                                         DEMORG1                
insight2061                                                    DEMORG1                
DefaultWorkspace-1cdf4300-dee5-4518-8c8c-feaa72a5chu1-lb0fld0h DEMORG1                
tsinfospringapp                                                DEMORG1                
Application Insights Smart Detection                           DEMORG1                
Failure Anomalies - insight2061                                DEMORG1                
ebautomation2d63gnquao4hu                                      TsInfoRG-deployment    
ebautomation2d63gnquao4hu/inputValidationRunbook               TsInfoRG-deployment    
TsInfoScaling                                                  DEMORG1                
TsinfoRT                                                       DEMORG1                
tsinfops                                                       DEMORG1                
demorg2913f                                                    DEMORG2                
ASP-DEMORG2-861c                                               DEMORG2                
demotstest                                                     DEMORG2                
vault196                                                       newresgroup            
Failure Anomalies - MyNewPythonFunctionApp                     MyNewResGrp         

You can see it below

Get-AzResource

Example-2:

The below Azure PowerShell cmdlet will help you to retrieve all the resources under the DEMORG2 resource group.

Get-AzResource -ResourceGroupName DEMORG2 | Format-Table

After executing the above cmdlet, I got the below output

PS C:\WINDOWS\system32> Get-AzResource -ResourceGroupName DEMORG2 | Format-Table

Name             ResourceGroupName ResourceType                      Location
----             ----------------- ------------                      --------
demoggh          DEMORG2           Microsoft.Storage/storageAccounts eastus  
demorg2913f      DEMORG2           Microsoft.Storage/storageAccounts eastus  
ASP-DEMORG2-861c DEMORG2           Microsoft.Web/serverFarms         eastus  
demotstest       DEMORG2           Microsoft.Web/sites               eastus  

Check out the output here

Get-AzResource PowerShell command

Example-3:

You can execute the below Azure PowerShell cmdlet that can help you to retrieve all the Azure resources with the provided name.

Get-AzResource -Name tsinfo | Format-List

After executing the above Azure PowerShell cmdlet, I got the below output.

PS C:\WINDOWS\system32> Get-AzResource -Name tsinfo | Format-List


Name              : TsInfo
ResourceGroupName : DEMORG1
ResourceType      : Microsoft.ServiceBus/namespaces
Location          : northeurope
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG1/providers/Microsoft.ServiceBus/namespaces/TsInfo
Tags              : 

You can see that here

 Get-AzResource command

Example-4:

Below Azure PowerShell cmdlet that can help you to get all the resources whose name matches with the specified wildcard.

Get-AzResource -Name tsinfo* | Format-Table

After executing the above Azure PowerShell cmdlet, I got the below output.

PS C:\WINDOWS\system32> Get-AzResource -Name tsinfo* | Format-Table

Name            ResourceGroupName ResourceType                                 Locatio
                                                                               n      
----            ----------------- ------------                                 -------
TsInfo          DEMORG1           Microsoft.ServiceBus/namespaces              nort...
tsinfospringapp DEMORG1           Microsoft.AppPlatform/Spring                 eastus 
TsInfoScaling   DEMORG1           Microsoft.DesktopVirtualization/scalingplans eastus 
TsinfoRT        DEMORG1           Microsoft.Network/routeTables                nort...
tsinfops        DEMORG1           Microsoft.DBforPostgreSQL/flexibleServers    eastus 

You can see that here

Get-AzResource cmdlet

Example-5:

You can also use the below Azure PowerShell cmdlet to retrieve the Azure resource based on the resource id.

Get-AzResource -ResourceId /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups/DEMORG1/providers/Microsoft.ServiceBus/namespaces/TsInfo

After executing the above Azure PowerShell cmdlet, I got the below output.

PS C:\Users\Bijay> Get-AzResource -ResourceId /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups/DEMORG1/providers/Microsoft.ServiceBus/namespaces/TsInfo


Name              : TsInfo
ResourceGroupName : DEMORG1
ResourceType      : Microsoft.ServiceBus/Namespaces
Location          : North Europe
ResourceId        : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5chu1/resourceGroups
                    /DEMORG1/providers/Microsoft.ServiceBus/namespaces/TsInfo
Tags              : 

You can see that below

powershell get-azresource

You may also like following the below articles

Wrapping Up

In this Azure PowerShell article, we have discussed the syntax and usage of the Get-AzResource Azure PowerShell cmdlet with examples. Thanks for reading this article !!!