I have a batch file which prompts the user a few times. I am looking to automate that with powershell. Is there any way to do this? I would need something like this:
Start-Process $InstallDir\Install.bat "y,*,$Version,y,y,y,y,y,y,y,y,y,y,y,y,y"
Depending on your batch file and what commands actually do the prompt, you might use input redirection
<. Put the prompts into a text file pine by line and redirect that into your batch file.
Supposing the batch file
prompts.bat contains the following commands...:
@echo off set /P VAR="Please enter some text: " echo/ echo Thank you for entering "%VAR%"! choice /M "Do you want to continue " if not ErrorLevel 2 del "%TEMP%\*.*" pause
...and the text file
prompts.txt contains the following lines...:
hello world Y n End
...the console output of the command line
prompts.bat < prompts.txt would be:
Please enter some text: Thank you for entering "hello world"! Do you want to continue [Y,N]?Y C:\Users\operator\AppData\Local\Temp\*.*, Are you sure (Y/N)? C:\Users\operator\AppData\Local\Temp\*.*, Are you sure (Y/N)? n Press any key to continue . . .
del command shows two prompts here as it receives the RETURN behind
Y which is not consumed by
choice; since an empty entry is not accepted, the promt appears one more time.)