获取我的 Azure 订阅中所有资源的列表(最好是 Powershell) [英] Get a list of all Resources in my Azure Subscription (Powershell Preferably)

查看:17
本文介绍了获取我的 Azure 订阅中所有资源的列表(最好是 Powershell)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 azure 订阅,我正在尝试编写一个 powershell 脚本来自动获取我订阅中当前拥有的所有资源(VM、存储帐户、数据库等)的列表.有没有办法使用 azure 管理 REST API 或 Azure Cmdlets 来做到这一点?

I have an azure subscription and I'm trying to write a powershell script to automatically get a list of all the resources (VMs, Storage Accounts, Databases, etc) that I currently have in my subscription. Is there a way to do this using the azure management REST API or the Azure Cmdlets?

推荐答案

如果您使用的是新的资源管理器模型(2014 年推出),您可以使用以下 PowerShell 脚本.

If you are using the new Resource Manager model (introduced in 2014) you can use the following PowerShell script.

Login-AzureRmAccount
Get-AzureRmResource | Export-Csv "c:Azure Resources.csv"

要使用资源管理器 PowerShell 命令,您将需要 AzureRM PowerShell 模块 (https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps).

To use the Resource Manager PowerShell commands you will need the AzureRM PowerShell module (https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps).

Install-Module AzureRM

有关资源管理器和经典模型之间差异的更多信息,请参见https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-deployment-model.

For more information on the difference between Resource Manager and Classic models see, https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-deployment-model.

对于有多个订阅的用户:如果要输出多个订阅的内容,则需要在调用Get-AzureRmResource之前先调用Select-AzureRmSubscription切换到另一个订阅.

For users with multiple subscriptions: If you want to output the contents of multiple subscriptions then you will need to call Select-AzureRmSubscription to switch to another subscription before calling Get-AzureRmResource.

这篇关于获取我的 Azure 订阅中所有资源的列表(最好是 Powershell)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆