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:
Start a new PowerShell session in the ISE or Command Prompt.
Execute Login-AzureRmAccount one last time for a given subscription and identity. Enter the username/password as required.
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.