Thursday, May 01, 2008

Storing and using a Password with PowerShell - Fun with ConvertTo-SecureString and ConvertFrom-SecureString

Rob Costello - Powershell Tip - Storing and Using Password Credentials

"So I've been doing quite a bit of Powershell scripting lately, and this little tid-bit came in very handy, so I thought I'd share it with you all.

In Powershell you can use the Get-Credential cmdlet to get alternate logon credentials when you need to perform a task from the shell.  But the Get-Credential cmdlet won't accept a hardcoded password in a script.  So, how do you write a script that needs to run without user intervention and needs to use credentials other than those of the account used to run it?

Well, here is the answer.

..."

A seemly safer approach to storing a password in an external file for later usage by Get-Credential. Much better than hard coding a plaintext password in the script (if you could do that...).

I'm not sure if this scares me or not (i.e. the saving of the password to a file)... but I still like it.

No comments: