How can I input "yes" as an answer to an interactive question in a PowerShell session? I know, in Bash, Yes
is the tool to answer "yes" on the prompt. In my situation, I can't suppress the prompt.
The script I'm running stops at
Please reply "yes" if you want to continue:
How powershell can run the script and "answer" yes when pompted?
ECHO 'Y' | Command-Name -Force.
Used without any command line parameters, the yes command behaves as though you were typing “y” and hitting Enter, over and over (and over and over) again. Very quickly. And it will carry on doing so until you press Ctrl+C to interrupt it.
The $_ is a variable or also referred to as an operator in PowerShell that is used to retrieve only specific values from the field. It is piped with various cmdlets and used in the “Where” , “Where-Object“, and “ForEach-Object” clauses of the PowerShell.
Using ECHO worked for me. I am running RSKeyMgmt.exe in my Powershell script and it prompted Yes(Y)/ No(N). So when I do
ECHO Y | RSKeyMgmt.exe...
It did not prompt the question and the command was executed correctly.
So I think ECHO 'someoption'
should work for other cases too.
I was also having the same issue. The solutions tried by me included:
However, none of them seemed to do the trick.
What finally solved the problem was:
Powershell-Cmdlet -Confirm:$false
It suppresses all confirmation prompts for the duration of the command and the command would be processed without any confirmation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With