Search code examples
azurepowershellazure-resource-group

How to export LocalNetworkGateway info from multiple Resource Groups


I'm new to powershell and azure and need to export all the LocalNetworkGateway information from multiple Subscriptions and Resource Groups.

I have a script to export from Resource Groups but I have to manually enter the ResourceGroupName for each one.

Is there a way to have a variable that contains all the ResourceGroupNames so that I don't have to run the script 40 times and manually enter a different ResourceGroupName for each?

Any help would be gratefully received.

I have code for one Resource Group at a time.

Get-AzLocalNetworkGateway -ResourceGroupName “RGName” | Export-Csv -Path "c:\Azure\LocalNetworkGateway.csv"

Solution

  • you can just iterate over resource groups:

    $resourceGroups = Get-AzResourceGroup
    $resourceGroups.foreach{ 
         Get-AzLocalNetworkGateway -ResourceGroupName $_.ResourceGroupName | 
             Export-Csv -Path "c:\Azure\LocalNetworkGateway.csv" -Append
    }