2

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 DevOps Automation A couple of weeks ago the rename / rebranding of Visual Studio Team Services to Azure DevOps was announced. The rebranding is a great step forward int...
AKS (Kubernetes) and no connection could be made because the target machine acti... A client of my had an error while connecting to different resources within their Kubernetes cluster in Azure (AKS). Kubectl error On the kubectl com...
Kubernetes (AKS) attached to Azure Storage (Files) Kubernetes (AKS) can be used for many situations. For a client we needed to make files available trough a Kubernetes Pod. The files needed to be share...
Resource Group deployment via ARM templates When deploying an Azure Resource Manager (ARM) template you have to create a resource group within Azure. To deploy a template via script your script ...
Azure Managed Service Identity and Local Development Instead of storing user credentials of an external system in a configuration file, you should store them in the Azure Key Vault. Before MSI (Managed S...
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 ...

2 Comments

  1. 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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.