Today I am sharing a way to encrypt the password & using it in powershell scripts.
I have used this way a few times now.
Attaching the code in below link & example on how to use it..
extract the zip file –> just run the batch file after that..
Enter the password that you want to encrypt.
encrypted password will be exported to securepassword.txt file.
Note:- Please encrypt the password on the same machine from where you will be running the script in which you will be using the password.
$password = read-host -prompt “Enter your Password”
write-host “$password is password”
$secure = ConvertTo-SecureString $password -force -asPlainText
$bytes = ConvertFrom-SecureString $secure
$bytes | out-file .\securepassword.txt
How to use it Code:-
$encrypted = “01000000d08c9ddf0115d1118c7a00c04fc297eb010000002”
$user = “lab\vikass”
$password = ConvertTo-SecureString -string $encrypted
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$password