title: How do I elevate a PowerShell script when run from Go?
body: <p>I am trying to execute a <code>.ps1</code> script that I made from GoLang. In order for the script to work I need to change the execution policy to <code>Unrestricted</code>. In order to set that I need PowerShell admin rights.</p>
  <p>Below is my code:</p>
  <pre class="lang-go prettyprint-override"><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;log&quot;
      &quot;os&quot;
      &quot;os/exec&quot;
  )
  
  func main() {
      app := &quot;powershell.exe&quot;
      restrict := &quot;powershell start-process powershell -verb runas&quot;
      path, err := os.Getwd()
      if err != nil {
          log.Println(err)
      }
      path = path + `\script\vpn.ps1`
      fmt.Println(path)
      restriction := &quot;Set-ExecutionPolicy -ExecutionPolicy Unrestricted&quot;
      confirmRestriction := &quot;Get-ExecutionPolicy&quot;
  
      power := exec.Command(restrict, restriction)
      std, err := power.Output()
      if err != nil {
          fmt.Println(err.Error())
          return
      }
      fmt.Println(string(std))
  
      verify := exec.Command(restrict, confirmRestriction)
      ver, err := verify.Output()
      if err != nil {
          fmt.Println(err.Error())
          return
      }
      fmt.Println(string(ver))
  
      fmt.Println(string(std))
      fmt.Println(&quot;ELEVATED: Set Execution Policy to Unrestricted&quot;)
  
      arg0 := &quot;-file&quot;
      cmd := exec.Command(app, arg0, path)
      stdout, err := cmd.Output()
      fmt.Println(&quot;Connecting to VPN&quot;)
  
      if err != nil {
          fmt.Println(err.Error())
          return
      }
  
      // Print the output
      fmt.Println(string(stdout))
  }
  </code></pre>
  <p>Whenever I run this it fails and when I try the PowerShell command (<code>powershell start-process powershell -verb runas</code>) directly at the command prompt I get this error:</p>
  <pre class="lang-none prettyprint-override"><code>-verb : The term '-verb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
  the spelling of the name, or if a path was included, verify that the path is correct and try again.
  At line:1 char:1
  + -verb runas
  + ~~~~~
      + CategoryInfo          : ObjectNotFound: (-verb:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
  </code></pre>
  <p>I am currently using go1.15.15 windows/amd64.</p>