Persisting Azure PowerShell logins

With the pre-1.0 Azure PowerShell cmdlets, my Azure login credentials were cached. Since making the switch to the 1.x release I’ve found that I need to execute Login-AzureRmAccount each new PowerShell session. This has been bugging me for a while and today I finally foudnm the time to figure out a way round it. I’m blogging it here mostly as a way to find it later so that I don’t have to figure it out again, but if it helps anyone else then that’s a nice added bonus ;-)

After a bit of searching I found this issue which steered me in the right direction.

To set up persistence, start a PowerShell session and authenticate (e.g. run Login-AzureRmAccount).

From that session, run

Save-AzureRmProfile –Path C:\your-path-here\AzureRmProfile.json

Then update your profile (I like to run “ise $profile”) to include

Select-AzureRmProfile –Path C:\your-path-here\AzureRmProfile.json | out-null

Et voila! Now when you create a new PowerShell session it will import the saved profile.

NOTE: YMMV: this is working for me so far – if it works for you too, that’s great! I’ve also only been running like this for less than a day, so don’t know how long I’ve got until the token expires, or whether it gets refreshed! Use at your own risk ;-)