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

The securitydata Azure resource group Most of the times companies have rules in place for managing their Azure environment. The main rules that should be in place are “Azure Policies” and ...
Point to Site VPN Client won’t install To connect an Azure App Service to a on-premise database you can make use of different solutions. Two of those solutions are: Hybrid Connection ...
Invoke Azure Function in your Visual Studio Team Services CI/CD pipeline A utility task is available for Visual Studio Team Services (VSTS) to invoke an http triggered Azure function. The ability to invoke a Function from y...
VSTS Extension for Azure Role Based Access Control Today I published an extension for Visual Studio Team Services (VSTS) that gives you the ability to add and remove role based access assignments in Az...
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...

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 *