A couple months ago, a friend who is now bewitched by supernatural powers of powershell (plus one for the team) asked me a question:
"Laerte, I do not have the luxury of being able to work with my SQL servers in Windows Authentication, I need to pass username and password"
“My friend, imagine passing
or My txt file :
Well as I have the pleasure of working with Windows Authentication, had not thought about yet (and thank goodness it was a friend, and the shame was not so big).
The solution seemed to be ready. I showed this to a friend and he told me:
That is what I want, but needs to be in my txt file with servers that I use on the powershell scripts. Something like: (servers.txt)
I thought a few milliseconds (hahaha sure I will not put real time, have to do my marketing) and the solution was ready.
First , we have do downloaded Library-StringCripto (many thanks to Steve) and you can download these functions in here.
This library is composed of two functions. One for encrypt and other to decrypt and the two procedures have to pass a password phrase. You can see more in the help functions.
Now, we have to create a txt file with encrypt passwords, and the code is :
And in the c:\temp\ServersSecurePassword.txt will be your Username and Password encrypted. Let’s take a look how the txt looks like ?
With ServerName, Username and Password separated by comma.
To Drecypt is more simple , using :
Just remember, the Password Phrase to decrypt must be the same to encrypt
Let´s say I want to use Invoke-DBMaint function from SQLPSX to perform a checkdb in system databases its only split, decrypt and be happy 🙂
This is why I do love Powershell.
Powershell Rocks !!!!
“The last fire will rise
Behind those eyes
Black house will rock
Blind boys dont lie
That voice so clear
Through broken walls
That scream I hear
Cry little sister (thou shall not fall)
Come come to your brother (thou shall not die)
Unchain me sister (thou shall not fear)
Love is with your brother (thou shall not kill)”