I am trying to iterate over all azure subscriptions, resource groups and resources
CodePudding user response:
You can use the below PowerShell script to pull the list of all subscriptions & their resource groups & resources in it.
Connect-AzAccount
$subs=Get-AzSubscription
foreach($sub in $subs){
Set-AzContext -Subscription $sub.id -Force
$resourcegroups= Get-AzResourceGroup
Write-Host "Currently connected to subscription"$sub.id -ForegroundColor red -BackgroundColor white
foreach($rg in $resourcegroups){
Write-Host "Current resourcegroup"$rg.ResourceGroupName -ForegroundColor Yellow -BackgroundColor Black
Write-Host "Here are list of resources present in this resource group:" -ForegroundColor Cyan
$resource=Get-AzResource -ResourceGroupName $rg.ResourceGroupName
Write-Output $resource.ResourceName
}
}
Here is the sample Output for reference:
CodePudding user response:


