How-To: Easily switch between multiple Azure accounts in PowerShell ISE without re-authenticating

If you work with Azure using the PowerShell ISE tool and have multiple subscriptions and/or login accounts, wouldn’t it be nice to be able to quickly switch the authentication account context without constantly logging in with new account credentials? I’ll show how to do this.

Basically, it involves using Add-AzureRMAccount to create a profile credential, Save-AzureRMProfile to save it, then some editing of the ISE profile file. Here’s how to do it:

  • Open the PowerShell ISE and run this command:
Add-AzureRmAccount -SubscriptionName "subscription name" -TenantId tenant GUID
  • This will open a login prompt. Enter the account credentials you wish to store. Then run this command:
Save-AzureRmProfile -Path [folder path]\[file name without an extension]

At this point, the credentials are saved locally.

  • Now, run this command:
notepad $profile
  • A Notepad window will appear. Add the following script, then save and close the ISE
function Add-Profile-Cred()
    Select-AzureRmProfile -Path [the full path to the file declared in step 4 above]

if (!($psISE.CurrentPowerShellTab.AddOnsMenu.Submenus | Where-Object { $_.DisplayName -eq "Add Profile Cred" }))
    $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Add Profile Cred",{Add-Profile-Cred},$null)

Note: the third argument to the Submenus Add() method could be a string denoting a keyboard shortcut (e.g. – “Ctrl+Shift+K”)

After re-starting the ISE, you should now see the new item appear in the Add-ons menu


Now you will be able to easily switch between different accounts (without logging in again)!


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s