Azure PowerShell ARM Profile

If you’re using Azure Resource Manager (ARM) cmdlets and debugging scripts in the ISE, it can be painful to keep executing Login-AzureRmAccount to establish a connection to the subscription on which you want to execute your code against.  As you know this requires one to enter and re-enter the username/password each time.

Instead you can do the following:

  1. Start a new PowerShell session in the ISE or Command Prompt.
  2. Execute Login-AzureRmAccount one last time for a given subscription and identity.  Enter the username/password as required.
  3. Execute Save-AzureRmProfile -Path C:\PSScripts\<username>_<subscriptionname>_Profile.apf where username is the account you need to use to execute your scripts and the subscriptionname is the name of the subscription to connect to.  This just helps keep these files organized if you are dealing with more than one account/subscription.  You may even want to include a date/time stamp in the filename since in most cases the username’s password will be subject to password expiration policy unless you’ve turned that off.

From that point forward all you need to do to enable PowerShell to login to that same Azure Subscription using the same username/password originally specified is:

Select-AzureRmProfile -Path C:\PSScripts\<username>_<subscriptionname>_Profile.apf

Just place it at the top of the script and don’t forget to remove it before putting it in Source Control. This is not the safest thing in the world, but certainly convenient for testing on your local machine as you debug your way through your code.

Posted in PowerShell

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

%d bloggers like this: