powershell send keys with $ not working correct here is the code
when i put the password with $ it types back as variable
$enter_password = Read-Host "Enter Your Password" -AsSecureString
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($enter_password))
$wshell = New-Object -ComObject wscript.shell;
Sleep 3
$wshell.SendKeys($password)
[System.Windows.Forms.SendKeys]::SendWait("$password")
exemple
password 1q2w3e$R%T^Y
i get 1q2w3e$R
how can i fix that?
CodePudding user response:
Try to escape special characters:
$enter_password = Read-Host "Enter Your Password" -AsSecureString
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($enter_password))
$wshell = New-Object -ComObject wscript.shell;
$wshell.Run("notepad")
$wshell.AppActivate("notepad")
Sleep 3
$password = $password.Replace('%', '{%}').Replace('^','{^}')
$wshell.SendKeys("$password")
write-host $password
