Azure Connection Assistant

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 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.

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

PSGallery-ACA

I initially create 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 PSGallery, 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 meat and potatoes of the code creates a new Key in your HKCU registry hive at [System\CurrentControlSet] called [SecCreds] the first time you use the New-SavedCreds function. New Keys are also created for each Credential 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.

Both the Library and the Module have 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.

Links:
https://www.powershellgallery.com/packages/AzureConnectionAssistant
https://github.com/deathbyvegemite/AzureConnectionAssistant
https://github.com/deathbyvegemite/AzureConnectionAssistant/blob/master/README.md
https://msdn.microsoft.com/en-us/library/ms995355.aspx

**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.