Azure Connection Assistant to Simplify Connecting to Azure RM via PowerShell

Azure Connection Assistant to Simplify Connecting to Azure RM via PowerShell

September 14, 2017

If you are like me, you connect to Azure via PowerShell sometimes dozens of times a day or more. I’m sure everyone has their shortcuts to make things like this quicker, and involve less typing, mine was to write some PowerShell.

At a basic level, the code adds some functions that allow you to save credentials in the Current User’s registry hive in an encrypted manner, and recall them to automatically connect, or validate an existing connection, to an Azure RM Subscription.

Install Azure Connection Assistant

The module is published on Microsoft’s PowerShell Gallery, making installation super easy.

Figure 1. Installing Azure Connection Assistant from the PowerShell Gallery

How I built the Azure Connection Assistant

I initially created just a PowerShell Library that could be dot sourced into a PowerShell session which I added to my PowerShell profile so it automatically loaded when I opened a PowerShell session.

For fun, I have now created a PowerShell module that can be installed from the PowerShell gallery, or downloaded from GitHub and dropped into your modules folder to provide the same functionality as the library.

Both the library and module can be downloaded from GitHub if you would like to experiment with them. All relevant links at the end of the post. Obligatory legal verbiage, all risk of use, and the results of use are with the user. This code is provided as is, with no warranty of any kind.

The PowerShell

The meat and potatoes of the code creates a new Key in your HKCU registry hive at [SystemCurrentControlSet] called [SecCreds] the first time you use the New-SavedCreds function. New Keys are also created for each Credential that you save.

Hint: Don’t make your names complicated, that’s what you use to recall them!

The UserName is stored in clear text and the Password is stored as a SecureString value which utilizes the built in Windows Data Protection (WDP) to encrypt the password in a way that only the user who created it, can decrypt it**. If you’d like to read more on WDP, the link is at the end of the post.

Disclaimer: WDP is a password based protection system ““ if your password to the local machine gets compromised, any credentials encrypted in the registry should also be considered burnt.

Both the library and the module have a full built-in help.

For the library:

PS C:Scripts> . .AzureConnectionHelperLibrary.ps1

Loading the library without the [-Silent] option will display full help for the Library as a whole and syntaxes for each function.

For the Module:

PS C:> help about_AzureConnectionAssistant 

This will display comprehensive help information, including the function syntax and examples on each functions usage.

Additional information can be found in the README.md file in the GitHub repository.

Useful Links

  1. Download AzureConnectionAssistant from PowerShell gallery
  2. Download AzureConnectionAssistant from GitHub
  3. View AzureConnectionAssistant  Readme
  4. Read more on Windows Data Protection WDP
  5. View PowerShell Gallery Readme