Skip to content
Menu
Tech Automation Blog
  • About Author
  • Contact
Tech Automation Blog

Complete Azure Inventory using Powershell

Posted on August 31, 2019February 27, 2022

Update : updated script to support Azure Az powershell module.

It is always great to have a script handy which will produce a quick azure resource inventory for your azure subscription. It may not contain all properties of azure resource types, however, just provide you information about the resource type, resource name, resource group etc.

To get detailed inventory of each resource type, refer to my other blogs in http://arindamhazra.com.

Login to Azure Account with Powershell and run this script. If you have multiple subscription associated with same Azure AD Tenant and if you credential is applicable for each of those subscription, it will generate inventory for all of them.

Before start using this script, make sure you have Azure Az Module installed and imported on the system. For more information on how to install and configure Az module refer following article : https://docs.microsoft.com/en-us/powershell/azure/new-azureps-module-az?view=azps-5.5.0

$date = Get-Date -UFormat("%m-%d-%y")
$currentDir = $(Get-Location).Path
$oFile = "$($currentDir)\All_Azure_Resources_$($date).csv"

if(Test-Path $oFile){
    Remove-Item $oFile -Force
}

"SubscriptName, ResourceGroupName,ResourceName,ResourceType,Tags" | Out-File $oFile -Append -Encoding ascii

Get-AzSubscription | ForEach-Object{
    $subscriptionId = $_.SubscriptionId
    $subscriptionName = $_.Name
    Set-AzContext -SubscriptionId $subscriptionId
    Get-AzResourceGroup | ForEach-Object{
        $resourceGroupName = $_.ResourceGroupName
        Get-AzResource -ResourceGroupName $resourceGroupName | ForEach-Object{
            $resourceName = $_.Name
            $resourceType = $_.Type
            if(!([string]::IsNullOrEmpty($_.Tags))){
                $tags = @()
                $_.Tags.GetEnumerator() |ForEach-Object {
                    [string]$tags += $_.key+ "=" + $_.value+ ";"
                }
            }
            else{
                $tags = ""
            }
            "$subscriptionName,$resourceGroupName,$resourceName,$resourceType,$tags" | Out-File $oFile -Append -Encoding ascii
        }
    }
}

Download above script and save it with a .ps1 file extension. Open powershell console and, login to your Azure account using – Login-AzAccount. It will prompt you to enter your Azure credentials.

This image has an empty alt attribute; its file name is image-3.png
Login to Azure

After you login to Azure, run the powershell script saved in previous step.

Run powershell script

A CSV file will be generated as shown below:

Output csv file

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
July 2025
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  
« May    

Recent Posts

  • Monitor and alert Azure Service Health issues May 5, 2020
  • AWS IAM User access review May 3, 2020
  • Integrate Azure Security Center with Event Hub April 28, 2020
  • Add Tags to Azure Subscription April 24, 2020
  • Automate Azure billing report in Excel March 6, 2020

Categories

©2025 Tech Automation Blog | Powered by SuperbThemes