As Technet Gallery is retiring so moving the code to Git Hub. (click below link, creating first link to my blog for those who are unfamiliar with github)

Encrypt Password and use it in Powershell Script

 

 

Hi Readers,

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

Reach me:- http://msexchange.me

 

 

PowerShell
Edit|Remove
$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:-
PowerShell
Edit|Remove
$encrypted = "01000000d08c9ddf0115d1118c7a00c04fc297eb010000000ffb51b2e604034a982598093219de570000000002000000000003660000c0000000100000004387d7a6f294bdcf25725159f7edaa390000000004800000a000000010000000efac6eb2cb924bf1cf893a9ddfdeeff71800000079b98b725901857051e84b78ba6e20da94752516a02833c114000000dbf49438a6ea07c06c3846fc23e725a081792782" 
$user = "lab\vikass" 
$password = ConvertTo-SecureString -string $encrypted 
 
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$password
 

Thanks for reading and downloading

Tech Wizard

http://techwizard.cloud

PowerShell Cheat Book