简体   繁体   中英

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"

you can just iterate over resource groups:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM