Listing Azure Services within a CSV file

In some situations you will look into a current Azure Environment and the setup/governance of it and need to migrate or move resources around.

The below script will help you with exporting the Azure resources into a CSV file, from that CSV file you can join the data within Excel to make plans.

Script

 

###################################################################################
##
## PowerShell script for exporting Azure Resources within a subscription.
## Creator: Maik van der Gaag
##
###################################################################################


Login-AzureRmAccount
$path = Read-Host "Enter the full path to save the export file to"

$subsciptions = Get-AzureRmSubscription

Write-Host "Subscriptions"
Write-Host "--------------"
foreach($sub in $subsciptions){

    Write-Host ($sub | Select -ExpandProperty "Name")
}

Write-Host ""

$name = Read-Host "Please enter the subscription names for which you want to export the Azure Services devided by (,)"

$names = $name.Split(",");

foreach($subName in $names){
    Write-Host "Exporting Subscription:" -ForegroundColor Green
    Set-AzureRmContext -SubscriptionName $subName
    Get-AzureRmResource | Select-Object Name, ResourceType, ResourceGroupName, SubscriptionId | Export-Csv -Path $path -Encoding ascii -NoTypeInformation -Append
}

Download

The script files can also be downloaded from GitHub.

https://github.com/MaikvanderGaag/MSFT-Scripts/tree/master/Export

Related Posts

Azure Event Grid with Custom Events As of yesterday (16-8-2017) the public preview of Azure Event Grid is live. Azure Event Grid is a fully managed event routing service. Azure Event Gri...
Removing the Classis Hybrid Connections from Azure (Azure BizTalk Service) As you know the classic hybrid connections that are build upon Azure BizTalk Services are deprecated. These connection will have to be replaced by the...
Restricting access to your Azure Web Application As you may know almost everything that is deployed to Azure is publicly available. As with Azure SQL Database you do not have a firewall available for...
Configure access to a private network for a Azure App Services On-Premise connections for Azure App Services can be created by using Hybrid Connections. Hybrid connections do not need any development or re-configu...
Extensions and Tips for deploying with Azure Resource Templates Working with Azure Services in different subscriptions means that the Azure Services need to run in different subscriptions. This often occurs when we...
Part 2 – Azure API Application to query the Azure SQL Database This post is the second in a series of three posts and will help you with the creation of identity pass-through authentication from a client applicati...

2 comments

  • getting error –

    Get-AzureRmResource : Method not found:
    ‘System.Collections.Generic.HashSet`1
    Microsoft.Azure.Commands.Common.Authentication.IClientFactory.get_UserAgents()’.
    At line:1 char:1
    + Get-AzureRmResource
    + ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : CloseError: (:) [Get-AzureRmResource], MissingMethodExceptio
    n
    + FullyQualifiedErrorId : Method not found: ‘System.Collections.Generic.HashSet`1 Microsoft.Azure.Commands.Common.Authentica
    tion.IClientFactory.get_UserAgents()’.,Microsoft.Azure.Commands.ResourceManager.Cmdlet
    s.Implementation.GetAzureResourceCmdlet

    Tried couple of times but same error.

    • Hi Sumit,

      You will have to install the AzureRM PowerShell module. You can check if you have it with the following command: Get-Module PowerShellGet -list | Select-Object Name,Version,Path. Other wise install it with this command: Install-Module AzureRM

Leave a Reply

Your email address will not be published. Required fields are marked *