简体   繁体   English

如何从多个ResourceGroup以及多个订阅中导出LocalNetworkGateway信息

[英]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.

相关问题 如何从多个资源组中导出LocalNetworkGateway信息 - How to export LocalNetworkGateway info from multiple Resource Groups 如何从多个订阅的Azure中导出VMData - How to export VMData from azure across multiple subscriptions 如何从多个Azure订阅中导出虚拟机名称和IP地址 - How to export Virtual Machine Names and IP Addresses from within multiple azure subscriptions Microsoft Azure:如何在跨多个订阅循环访问资源的脚本中更改订阅 - Microsoft Azure: How to change subscriptions in a script that iterates through resources across multiple subscriptions Azure - 信用分布在多个订阅中 - Azure - Credit spread across multiple subscriptions Azure Powershell - 跨 EA 中的多个订阅 - Azure Powershell - across MULTIPLE subscriptions in an EA Azure 服务连接无法跨多个订阅工作 - Azure Service Connection not working across multiple subscriptions 如何一次性从多个订阅中读取数据 - How to read the data from multiple subscriptions at one go 如何跨多个订阅加密所有Azure存储帐户中的现有数据 - How can I encrypt existing data in ALL Azure storage accounts across multiple subscriptions Azure功能的托管身份可以跨多个订阅进行访问吗? - Can Managed Identity of a Azure Function have access across multiple subscriptions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM