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

Showing posts with label Profile. Show all posts
Showing posts with label Profile. Show all posts

Sunday, June 12, 2016

Reload PowerShell Profile

When editing your PowerShell profile, you need to reload the profile to check or implement your changes.  There are three ways to accomplish this.


  1. Start a new PowerShell session
  2. Type the command & $Profile
  3. Type the command . $Profile


Way one is inconvenient.
Way two invokes the $Profile script.
Way three sources the $Profile script.

Are two and three really different?  Dunno, the end result is the same.

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!

About Me

My photo
A living, breathing contradiction.