# 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