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
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>
4 Replies to “Auto Answer “Yes/No” to Prompt – PowerShell & CMD”
saying invalid input
When I run this:
ECHO Y | VSSADMIN DELETE SHADOWS /FOR=C: /ALL >>c:\rjcache\vssadmin.txt
My result is:
vssadmin 1.1 – Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001-2013 Microsoft Corp.
Do you really want to delete 1 shadow copies (Y/N): [N]? N
I ran into the same issue, for vssadmin you can use the /quiet switch instead of echo y.
Worked for me, Thanks!