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

后端 未结 5 1703
旧时难觅i
旧时难觅i 2020-12-16 13:53

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

相关标签:
5条回答
  • 2020-12-16 13:57

    I was trying to kill a pesky startup program and found that the Stop-Process and / or the program would not accept a piped input (no Echo Y | for me!) but I changed JPs answer a little bit: Stop-Process -name [program.name] -Force ; ran as administrator and it worked like a charm.

    0 讨论(0)
  • 2020-12-16 14:00

    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.

    0 讨论(0)
  • 2020-12-16 14:05

    Inspired by other answers, here is my example:

    ECHO Y | powershell Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
    
    0 讨论(0)
  • 2020-12-16 14:07

    You can test these old fashion ways :

    Cmd /c "GpUpdate.exe /FORCE <C:\temp\response.txt"
    
    ECHO 'Y' | GpUpdate.exe /FORCE
    
    Get-Content "C:\temp\response.txt" | GpUpdate.exe /FORCE
    
    0 讨论(0)
  • 2020-12-16 14:18

    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.

    0 讨论(0)
提交回复
热议问题