Have you ever received hazzel from the security guy when you store passwords in installation and/or configiguration files. Been there, done that 🙂
But Powershell provide a feature to avoid this problem. The follwing code lines will retrieve a password from the user as crypted string (first line). The following two lines will convert the crypted password to a readable string than can be passed to setup programs. The last line (number 4), will print the password.
$password = Read-Host -Prompt "Enter default password" -AsSecureString $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password) $psw = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) Write-Host $psw
I will most likely use this in my semi-automatic scripts when I shall install SQL Server, and pass the $psw to the setup.exe program as a command-line parameter as follow:
D:\setup.exe /configurationfile="C:\SQLInstall\ConfigurationFile.ini" /SAPWD=$psw /SQLSVCPASSWORD=$psw /AGTSVCPASSWORD=$psw /ISSVCPASSWORD=$psw