Auto Answer “Yes/No” to Prompt – PowerShell & CMD

Some scripts or commands executed in Windows PowerShell or CMD may ask interactive questions that have to be responded with “Yes” or “No” answers.

To know how to answer these interactive questions automatically is very handy for different automations.

In this note i will show how to respond “Yes” or “No” to prompts in Windows PowerShell & CMD automatically.

Cool Tip: Get the return code from the last command or application! Read more →

Auto Answer “Yes/No” to Prompt

Pipe the echo [y|n] to the commands in Windows PowerShell or CMD that ask “Yes/No” questions, to answer them automatically.

Auto answer “Yes”:

PS C:\> echo y | <command>

Auto answer “No”:

PS C:\> echo n | <command>