Save profiles for all Azure subscriptions in one go

As discussed in one of the previous blog posts, we can use PowerShell to help create persistent logins. Now consider scenario, where you have access to multiple azure subscriptions. Off course, you can download and save AzureRM profile for each one of the them. However, there are two major issues:

  1. AzureRM profile downloaded is associated with a token by default and it expires in a few days.
  2. If you have too many subscriptions, it can be tiresome to first select subscription and then save the profile.

Below is one of the ways that you can use to automatically save profiles for all of your associated subscriptions:

$SubscriptionNames = Get-AzureRmSubscription | Select SubscriptionName
foreach($SubscriptionName in $SubscriptionNames.SubscriptionName){
 Select-AzureRMSubscription -SubscriptionName $SubscriptionName
 Save-AzureRMProfile -Path "C:\$SubscriptionName.json"

Now, you can load all of these json files in your PowerShell profile and easily use them.

If you are latest version of PowerShell – please refer to for updated commands.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s