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>
Was it useful? Share this post with the world!

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

  1. saying invalid input

  2. 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

  3. I ran into the same issue, for vssadmin you can use the /quiet switch instead of echo y.
    Source: https://stackoverflow.com/questions/15147900/how-to-supply-console-input-yes-no-as-part-of-batch-file-on-windows

  4. Mywiah Monkweh says: Reply

    Worked for me, Thanks!

  5. Thanks it worked for me.

Leave a Reply