Get a list of all Resources in my Azure Subscription (Powershell Preferably)

*爱你&永不变心* 提交于 2019-11-26 23:36:29

问题


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?


回答1:


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"

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

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.

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.




回答2:


I don't think there's just one function (or PS Cmdlet) to fetch all this information. However each of these can be fetched through both Windows Azure Service Management REST API as well as Window Azure PowerShell Cmdlets.

Windows Azure Service Management REST API: http://msdn.microsoft.com/en-us/library/windowsazure/ee460799.aspx. For example, if you want to list storage accounts in your subscription, you would use this: http://msdn.microsoft.com/en-us/library/windowsazure/ee460787.aspx

Windows Azure PowerShell Cmdlets: http://msdn.microsoft.com/en-us/library/jj554330.aspx. Again, if you want to list storage accounts in your subscription, you would use this: http://msdn.microsoft.com/en-us/library/dn205168.aspx.




回答3:


well, You may update the version of your AzurePowershell and execute this command.

Get-AzureResource

In the output, You may check for "ResourceType". It has the information about the type of resource creatd on azure.




回答4:


Adding to @Gaurav's answer (and related to your comment about SQL database enumeration): You can enumerate all of your databases, on a per-server basis, in a few easy steps.

First, enumerate all of the SQL Database servers in your subscription:

Then, for each server, create a connection context and enumerate the databases. Note that, with the Get-Credentials cmdlet, I was prompted to enter a username + password via a popup, which I don't show here. For demonstration purposes, I created a brand new server, with only a master database, to show what the output looks like:




回答5:


This sample demonstrates how to automatically get a list of all the resources (VMs, Storage Accounts, Databases, App Services) and status via Powershell by certificate authentication.

https://gallery.technet.microsoft.com/Access-Azure-resource-data-ca9cc9f7




回答6:


Since you said PowerShell "preferably", I'm going to assume other options are still maybe useful? You can go to http://manage.windowsazure.com, and click on All Items. Then you can copy/paste the table into Excel. You'll have to do it once per page, but it's still faster and more comprehensive than having to run a variety of cmdlets. That's assuming you have at least a few types of resources and not more than a few pages of resources.

You have to take 30 seconds to do a little cleanup in Excel, but for what I'm trying to do right now, this was definitely the best & fastest solution. I hope it's useful to you (or someone else) too.



来源:https://stackoverflow.com/questions/17584084/get-a-list-of-all-resources-in-my-azure-subscription-powershell-preferably

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!