Here’s a quick script, it loop through the subscriptions matching the -like String, it will then get give all the resource group names, resource names and types, this then output to a .csv file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# This script lists all subscriptions with a name "like" then outputs all the RG and Resource into a CSV # Create an array to store the data $data = @() # List subscriptions containing the word "LATAM" $subscriptions = Get-AzSubscription | Where-Object { $_.Name -like '*Production*' } foreach ($subscription in $subscriptions) { Set-AzContext -SubscriptionId $subscription.Id $resourceGroups = Get-AzResourceGroup foreach ($resourceGroup in $resourceGroups) { $resourceGroupName = $resourceGroup.ResourceGroupName $resources = Get-AzResource -ResourceGroupName $resourceGroupName foreach ($resource in $resources) { # Create a custom object with the required properties $resourceData = [PSCustomObject]@{ SubscriptionName = $subscription.Name ResourceGroupName = $resourceGroupName ResourceName = $resource.Name ResourceType = $resource.ResourceType } # Add the custom object to the data array $data += $resourceData } } } # Export the data to a single CSV file $exportPath = "C:\temp\AllResources.csv" $data | Export-Csv -Path $exportPath -NoTypeInformation |
This will give you an output like this