The ramblings of an old IT Pro travelling the digital byways.

Saturday, June 11, 2016

Persisting Azure RM Credentials: Profile switch in PowerShell

I manage a number of Azure subscriptions for my employer. One of the things that used to drive me nuts is having to constantly go through the Login process, especially since we use Multi Factor Authentication, and then having to switch back and forth between subscriptions.

I recently stumbled across an blog about the Save-AzureRmProfile command. Did I mention I'm relatively new to Azure? While blog provided useful information and simplified things for me, I took it one step further (have to give my buddy Rick credit for sparking the idea).

 I saved a profile file for each one of my subscriptions,

    Save-AzureRmProfile -Path C:\users\Brian\Documents\Azure\Profiles\AzureRmDevProfile.json 

then edited my PowerShell profile to include a function for each profile (hint: if you don't have a PowerShell profile, New-Item –type file –force $profile).

    function goDev { 
        Select-AzureRmProfile -Path C:\users\Brian\Documents\Azure\Profiles\AzureRmDevProfile.json 

Now, if I want to switch to my development subscription while in PowerShell, I simply type "goDev" and I'm there. I have a separate go function for each of the subscriptions I manage.

Saving my Azure profiles and modifying my PowerShell profile: 20 minutes.
Eliminating yet another pesky annoyance: Priceless!

No comments:

About Me

My photo
A living, breathing contradiction.