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
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