Looping through your Azure subscriptions using PowerShell

Share this:

When working with multiple subscriptions in Azure, more than often we will have to loop through the available subscriptions to list or change resources.

Solution


The solution is simple, basically we use a variable to receive all existent subscriptions (make sure that you are connected into your Azure), and then we loop every subscription and inside of that ForEach we can run our cmdlets.

Here is a piece of code that does exactly that. If you want help to connect in your azure, you can use Connect-AzureRMAccount.

$subscriptions=Get-AzureRMSubscription

ForEach ($vsub in $subscriptions){
Select-AzureRmSubscription $vsub.SubscriptionID

Write-Host

Write-Host “Working on “ $vsub

Write-Host

Get-AzureRmVM | Select Name,REsourceGroupName,Location

}

Written by Anderson Patricio

Anderson Patricio

Anderson Patricio is a Canadian MVP in Cloud and Datacenter Management, and Office Server and Services, besides the Microsoft Award he also holds a Solutions Master (MCSM) in Exchange and several other certifications. Anderson has been contributing to the Microsoft Community with articles, tutorials, blog posts, twitter, forums and book reviews. He is a regular contributor here at ITPROCentral.com, MSExchange.org, Techgenix.com and Anderson Patricio.org (Portuguese).

Related Post

Using Tags in Microsoft Azure When using Azure Resource Manager deployment model the administrator can use Tags, which helps to organize resources and categorize them in a simple w...
Retrieving the GUID of installed applications on y... If you are managing desktop applications or working on DSC packages, the GUID of installed application will be required at some point of your journey....
Top 5 of the Week: Week of May 8th Folks, Here are the top 5 IT news for this week. Quick guide to Windows 10 training and certification for IT pros https://blogs.technet...
How to install Microsoft Azure PowerShell In this Tutorial we are going over the process to install Microsoft Azure PowerShell and we can use the same procedure to update several other compone...