title: How can I automate running a PowerShell script that prompts UI for choice?
body: <p>I have a powershell script p1.ps1 that looks like this (not exactly, but this would do as an example):</p>
  
  <pre><code>$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&amp;Yes", "Do the action."
  $no = New-Object System.Management.Automation.Host.ChoiceDescription "&amp;No", "Exit."
  $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
  $result = $host.ui.PromptForChoice($title, $message, $options, 1)
  </code></pre>
  
  <p>How can I write another script p2.ps1, that will run the first one (p1.ps1) and provide it with an answer to the prompt, so that p2.ps1 executes with no questions asked?</p>
  
  <p>I have tried:</p>
  
  <pre><code>echo y | p1.ps1
  </code></pre>
  
  <p>but it does not do the trick.</p>