LeVeilleur.net

Subscribe

Archive for the ‘powershell’

PowerShell : Encrypt Password in text file

février 03, 2009 By: Christopher Keyaert Category: powershell No Comments →

Hello tout le monde,

Voici un petit bout de code PowerShell vous permettant de crypter les mots de passes que vous utilisez dans vos scripts.

read-host -prompt "Enter password to be encrypted in file.pwdt " -assecurestring | convertfrom-securestring | out-file file.pwd

$pass = cat file.pwd | convertto-securestring
$ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass)
$pass_back = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($ptr)

write-output "password decrpyted is: $pass_back"