[英]How to export LocalNetworkGateway info from multiple ResourceGroups but also across multiple subscriptions
I'm new to powershell and azure and need to export all the LocalNetworkGateway information from multiple Resource Groups but also from across multiple Subscriptions. 我是Powershell和Azure的新手,需要从多个资源组以及多个订阅中导出所有LocalNetworkGateway信息。
A contributor has kindly provided me with a script that can output the data from multiple Resource Groups within a single subscription but I need to find a way of doing this across all subscriptions without having to set the subscription context manually for each one and then running the script for each subscription. 一个贡献者为我提供了一个脚本,该脚本可以在单个订阅中输出来自多个资源组的数据,但是我需要找到一种在所有订阅中执行此操作的方法,而不必手动为每个订阅设置订阅上下文,然后运行每个订阅的脚本。
I have used the 我用过
$azureSubs = Get-AzSubscription
as a way of extracting information across multiple subscriptions that does not require Resource Group Names but I am now stuck. 作为一种在多个订阅中提取信息的方法,这种方法不需要资源组名称,但是我现在陷入困境。 The code below has successfully provided info across RG's but within a single subscription.
下面的代码已成功地在RG的各个订阅中提供了信息。
$resourceGroups = Get-AzResourceGroup
$resourceGroups.foreach{
Get-AzLocalNetworkGateway -ResourceGroupName $_.ResourceGroupName |
Export-Csv -Path "c:\Azure\LocalNetworkGateway.csv" -Append
}
you need to create another loop around subscription (similar to resource groups), the only trick is that you need to switch active subscription before doing requests to the subscription: 您需要围绕订阅创建另一个循环(类似于资源组),唯一的技巧是您需要在对订阅进行请求之前切换活动订阅:
$azureSubs = Get-AzSubscription
$azureSubs.foreach{
Select-AzSubscription $_ # << change active subscription
$resourceGroups = Get-AzResourceGroup # << same resource group loop starts here
$resourceGroups.foreach{
Get-AzLocalNetworkGateway -ResourceGroupName $_.ResourceGroupName |
Export-Csv -Path "c:\Azure\LocalNetworkGateway.csv" -Append
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.