Just another WordPress site

PHP CLI Password Prompts on Windows 7

There are serveral solutions to gather passwords with PHP CLI on Windows. But usually they do not work with Windows 7.
So this is my solution using Powershell:

// please set the path to your powershell, here it is: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
$pwd=shell_exec('C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Command "$Password=Read-Host -assecurestring \"Please enter your password\" ; $PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)) ; echo $PlainPassword;"');
$pwd=explode("\n", $pwd); $pwd=$pwd[0];
echo "You have entered the following password: $pwd\n";

Leave a comment for: "PHP CLI Password Prompts on Windows 7"

You must be logged in to post a comment.