title: How to force session level execution policy without prompt in PowerShell?
body: <p>I use the following code to rerun a script with admin privilege if necessary.  </p>
  
  <pre><code># Require admin
  if(!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
      Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
      exit
  }
  </code></pre>
  
  <p>However, on some systems, when I right click the script and choose <em>run with powershell</em>, it will prompt me for something like <strong>yes, no, all, cancel... etc</strong>. I don't know exactly when this will happen. How can I <strong>force</strong> the execution policy change without the prompt aforementioned? I checked the document and it seems there is no <code>-force</code> parameter for <code>powershell</code>. There is a <code>-force</code> parameter for the cmdlet <code>set-executionpolicy</code> though. </p>