If I use below simple code to mask input in command prompt and put in a batch file it works as expected:
Working code:
echo off
set "psCommand=powershell -Command "$pword = read-host 'Enter Password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
echo %password%
pause
But when I put the similar thing to mask input inside if condition as below it does not work:
@echo off
setlocal enabledelayedexpansion
cd /d "C:\Program Files\IIS\Microsoft Web Deploy V3"
echo Please select any option from below list:
echo 1. Get The Dependencies
echo 2. Export the IIS settings
echo 3. Import the IIS settings
set /p INPUT=""
IF /I '%INPUT%'=='1' (msdeploy -verb:getDependencies -source:metakey=lm/w3svc)
IF /I '%INPUT%'=='2' (echo Please provide the path to export IIS settings:
set /p EXPORTPATH=""
set "psCommand=powershell -Command "$pword = read-host 'Enter Password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
echo %password% !EXPORTPATH!
msdeploy.exe -verb:sync -source:apphostconfig -dest:package=!EXPORTPATH!\IISPackage.zip,encryptPassword=%password%> DWSpackage7.log
echo LINE IS EXECUTED
)
IF /I '%INPUT%'=='3' (echo Please provide the zip file with complete path to import IIS settings:
set /p IMPORTPATH=""
echo Please provide the password to import the iis settings:
set /p IMPORTPASSWORD=""
msdeploy.exe -verb:sync -source:package=!IMPORTPATH!,encryptPassword=!IMPORTPASSWORD! -dest:apphostconfig> DWSpackage7.log
)
pause
Please have a look and suggest me where I'm doing mistake or if I'm missing anything.
Aucun commentaire:
Enregistrer un commentaire