PowerShell Genie

Az.Resources module: setup and commands

Module 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Inventory Azure resources with Get-AzResource and Get-AzResourceGroup, then scope changes carefully by subscription, resource group, type and tag.

Getting it

Install-PSResource -Name Az.Resources from the PowerShell Gallery. It pulls Az.Accounts in as a dependency.

Examples

1PS> Get-AzResource -ResourceGroupName rg-app
Show reference output
1 ResourceGroupName Name ResourceType Location
2 ----------------- -------- --------------------------------- --------
3 RG-PROD WEB01 Microsoft.Compute/virtualMachines eastus
4 RG-PROD stprod01 Microsoft.Storage/storageAccounts eastus
1PS> Get-AzRoleAssignment -Scope /subscriptions/ 00000000 - 0000 - 0000 - 0000 - 000000000000
Show reference output
1 DisplayName RoleDefinitionName Scope
2 ----------- ------------------ -----
3 Adele Vance Reader /subscriptions/1111...

What it is for

Use it for cross-service inventory, because Get-AzResource returns every resource type in one pass. It is also where role assignments and policy assignments get read for an access review.

Typical tasks

  • Inventory every resource in a subscription
  • Find resources missing a required tag
  • List resource groups with their locations
  • Report role assignments at a given scope
  • Review deployment history for a resource group
  • Locate resources by tag value

Check the installed version

1PS> Get-Module -ListAvailable Az.Resources | Select-Object Name, Version, Path
2PS> Get-Command -Module Az.Resources

Compare the module path and version with the session used by your scheduled task or automation account. Use it for cross-service inventory, because Get-AzResource returns every resource type in one pass. It is also where role assignments and policy assignments get read for an access review.

Primary documentation

Active Directory PowerShell documentation

Continue
Genie guideAz.Resources module: setup and commands

Inventory Azure resources with Get-AzResource and Get-AzResourceGroup, then scope changes carefully by subscription, resource group, type and tag.