Powershell command used in BAT file is eliminating the escape character available in the password specified by user in the console and saving it in a file.
I have a BAT script which prompt the user to specify the password in console. Password should be masked as ***** while user typing it in console. Password will be something like wel!123. This password is saved into variable and finally getting copied to a text file. I got few suggestion use the below code in my BAT file, but the escape character in the actual password( Wel!123) is getting eliminated and saving the password as Wel123 into login.txt file.
SetLocal
set "psCmd=powershell -Command "$pwd = read-host 'Enter Your Password' -
AsSecureString; $BSTR=
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd);
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /F "usebackq delims=" %%# in (`%psCmd%`) do set "pwd=%%#"
@echo %pwd%>>login.txt