Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I automatically answer "yes" to a prompt in Powershell?

Tags:

powershell

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?

like image 475
Frown Avatar asked Dec 28 '12 14:12

Frown


People also ask

How do I use yes to all in PowerShell?

ECHO 'Y' | Command-Name -Force.

How do I use YES in CMD?

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.

What does $_ do in PowerShell?

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.


2 Answers

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.

like image 98
Dongminator Avatar answered Oct 24 '22 08:10

Dongminator


I was also having the same issue. The solutions tried by me included:

  • ECHO 'Y' |
  • Command-Name -Force
  • $ConfirmPreference = 'None'

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.

like image 13
AJain2810 Avatar answered Oct 24 '22 09:10

AJain2810