PowerShell Genie

Find Azure resources missing required tags

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Inspect Azure resource tags with Get-AzResource and identify resources missing required keys before planning any changes.

The script

1PS> $required = 'Owner', 'Environment', 'CostCenter'
2PS> Get-AzResource | ForEach-Object {
3PS> $resource = $_
4PS> $missing = $required | Where-Object {
5PS> -not $resource.Tags -or
6PS> -not $resource.Tags.ContainsKey($_) -or
7PS> [string]::IsNullOrWhiteSpace($resource.Tags[$_])
8PS> }
9PS> if ($missing) {
10PS> [pscustomobject]@{
11PS> ResourceGroup = $resource.ResourceGroupName
12PS> Name = $resource.Name
13PS> Type = $resource.ResourceType
14PS> MissingTags = $missing -join ', '
15PS> }
16PS> }
17PS> } | Sort-Object ResourceGroup, Name

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    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
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    $required = 'Owner', 'Environment', 'CostCenter' Get-AzResource | ForEach-Object { $resource = $_ $missing = $required | Where-Object { -not $resource.Tags -or -not $resource.Tags.ContainsKey($_) -or [string]::IsNullOrWhiteSpace($resource.Tags[$_]) } if ($missing) { [pscustomobject]@{ ResourceGroup = $resource.ResourceGroupName Name = $resource.Name Type = $resource.ResourceType MissingTags = $missing -join ', ' } } } | Sort-Object ResourceGroup, Name
    1. Stage 1$requiredPositional values or no named parameters
    2. Stage 2ForEach-ObjectPositional values or no named parameters
    3. Stage 3Sort-ObjectPositional values or no named parameters

      How it works

      Inspect Azure resource tags with Get-AzResource and identify resources missing required keys before planning any changes. Each resource is checked against one explicit required-tag list, and only gaps become output. Keeping discovery separate from remediation makes the report safe to run during governance reviews.

      Adapting it

      Replace the required list with your policy names or load it from configuration. Scope Get-AzResource to a subscription or resource group when the tenant is large.

      Primary documentation

      Where-Object reference · ForEach-Object reference · Sort-Object reference

      Continue
      Genie guideFind Azure resources missing required tags

      Inspect Azure resource tags with Get-AzResource and identify resources missing required keys before planning any changes.