View resources and their details in an Azure subscription.

Lesiba A. Serite 26 Reputation points
2022-05-25T07:47:24.1+00:00

Is there a way to list all the resources along with their specifications in an Azure subscription?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,081 questions
0 comments No comments
{count} votes

Accepted answer
  1. shiva patpi 13,131 Reputation points Microsoft Employee
    2022-05-26T21:40:58.753+00:00

    Hello @Lesiba A. Serite ,
    I am just trying to expand Ravikanths answer with couple of guidelines and with sample cmdlets so that you can get started , please see the comments for each line so that you can understand better and expand it accordingly !

    $Resources = Get-AzureRmResource #It will give all the resource names
    foreach($resource in $Resources) #looping through each resource
    {
    if ($resource.ResourceType -eq "Microsoft.Compute/virtualMachines") # if the resource type is VirtualMachines
    {
    Get-azvm -resourcegroupname $resource.ResourceGroupName -Name $resource.Name #Call get-azVM to get VM details
    }
    elseif ($resource.ResourceType -eq "Microsoft.Storage/storageAccounts") # if the resource type is StorageAccounts
    {
    Get-AzureRmStorageAccount -resourcegroupname $resource.ResourceGroupName -Name $resource.Name #Get the details of storage account
    }
    }

    Sample Output

    VM Details

    206011-image.png

    Storage Details:

    205917-image.png

    Get-AzureRMResource cmdlet returns lot of information , so you can filter it out by selecting the particular column

    205928-image.png

    In the above code, you can always narrow down to only specific attributes:
    For example : for storage to get the particular storage account information:
    $str = Get-AzureRmStorageAccount -resourcegroupname "rgname" -Name "accountname"
    if you want to query specific attribute you can use $str.kind , $str.SkuName etc.

    205969-image.png

    Above script is querying only for VMs , Storage Accounts based upon the if condition - you can expand the script based upon your requirements !

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Ravi Kanth Koppala 3,231 Reputation points Microsoft Employee
    2022-05-25T09:10:11.653+00:00

    @Lesiba A. Serite ,
    Thank you for reaching out to the Microsoft Q&A platform. I understand you want to extract the list of resources along with their subscription details in an Azure subscription. Happy to answer your question.

    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
    Install-Module AzureRM

    For more information on the difference between Resource Manager and Classic models see, https://learn.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.

    ----------

    Please "Accept as Answer" and Upvote if any of the above helped so that, it can help others in the community looking for remediation for similar issues.