Storing Credentials for PowerShell

When working locally on PowerShell scripts I am quite frequently re-running them; and rather then let my self hard-code my credentials into my script which would be the easy (and less secure) thing to do, I did some digging to figure out now to securely store them.

$credpath = "v:\crypt\token.xml"
Get-Credential |  Export-CliXml $credpath

This will prompt for an interactive dialog box where you enter your password, and it is then written as a secure string to an xml file to the path identified.

Now this can easily be used in a number of scripts on the local machine without the need to enter credentials interactively which is helpful for repeated runs and automation scenarios as well where there might not always be an interactive UI.

$credpath = "v:\crypt\token.xml"
$cred = import-clixml -path $credpath

This file can only be used by the user and the machine where it was created; you should keep the file somewhere secure like an encrypted USB Drive or VeraCrypt partition.

If you happen to use two user accounts or two machines you can test this by running this script that will display your password on the user account and machine where the credential was created, and fail on an account or machine where it was not.  Note don’t do this in front of an audience.

$credpath = "v:\crypt\token.xml"

$cred = import-clixml -path $credpath
write-host $cred.GetNetworkCredential().password

I have found this a very helpful way to cut down my runtime when building out powershell scripts as well as prevent accidently committing or sharing my credentials with a co-worker.

 

Advertisement

Getting started in the Cloud

IT has gone under a wide range of technology shifts over the past several years, as storage prices have continued to drop, vitalization hanging the nature of server rooms, broadband and mobility providing internet connections all the time.

These technologies have come together and are the foundation of what we call the cloud, massive storage, compute and practically infinite global scale. In many ways it is similar to the mainframe computers that dominated the 70s and 80s before the desktop computer revolution.

Mastering new technologies has always been a critical part of a successful IT career, but the pace of change technology has never been faster, Microsoft has set up a cloud essentials subscription for IT Pro’s to have access to try these new technologies.

https://www.itprocloudessentials.com/

This is a good hub to get familiar with the various parts of the Azure Stack and how to work with it in a familiar application language.

Microsoft is also previewing a new platform to distribute additional documentation to developers in an easier to browse fashion.  It is currently previewing content for the Enterprise Mobility Suite that is part of the Office 365 offering.

https://docs.microsoft.com/