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.
After you login to Azure, run the powershell script saved in previous step.
A CSV file will be generated as shown below: