I have a batch file that accept input from the user for the password. It does not take the last character for some reason and I cannot figure it out.
powershell -Command $pword = read-host "Enter password " -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) > .tmp.txt & set /p password=<.tmp.txt & del .tmp.txt
echo psexec \\%computerName% -u %domainName%\%userName% -p %password% cmd
I know it is not the powershell command because I tested it with set /p password="Enter password: "
and still fails to echo the last character.
As per my comment, here are the if statements I used:
set /P domainName=
set params = %*:"=""?!
if "%domainName%" == "1" (
set "domainName=domain1"
goto nextstep
)
if "%domainName%" == "2" (
set "domainName=domain2"
goto nextstep
)
if "%domainName%" == "3" (
set "domainName=domain3"
goto nextstep
) else (
goto resetfile
)
:nextstep
My problem is that for 2 of the 3 domains, psexec runs. For domain1, it does not run. I echoed out the command, and it prints perfectly. When I remove echo
from the command, it skips all of that and restarts the file.
nextstep
is:
:nextstep
set /p userName="Enter your Admin username: "
powershell -Command $pword = read-host "Enter password " -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) > .tmp.txt & set /p password=<.tmp.txt & del .tmp.txt
psexec \\%computerName% -u %domainName%\%userName% -p %password% cmd
:resetfile
set resetfile=
set /p resetfile="Do you want to restart this file? Press 'y' for Yes or 'n' for No then Press ENTER: "
if not '%resetfile%'=='' set resetfile=%resetfile:~0,1%
if '%resetfile%'=='y' goto start
The script does not even ask if I want to restart the script. It just loops back to :start
, which is at the beginning of the script.
Please help, thank you!