title: restart powershell with admin rights and continue with current script
body: <p>i am trying to check if powershell has admin rights. That is pretty simple and works fine but my problem is that powershell doesn't continue in the new instance with the script after it opens the new instance. The new instance runs in System32.</p>
  
  <p>The new instance just shows: <code>PS C:\windows\system32&gt;</code></p>
  
  <p>Is it also possible to close the first instance that is running after the second instance started?</p>
  
  <pre><code>function checkRights {
  $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
  $princ = New-Object System.Security.Principal.WindowsPrincipal($identity)
      if(!$princ.IsInRole( `
      [System.Security.Principal.WindowsBuiltInRole]::Administrator))
     {
       $powershell = [System.Diagnostics.Process]::GetCurrentProcess()
       $psi = New-Object System.Diagnostics.ProcessStartInfo $powerShell.Path
       $installPath = $MyInvocation.MyCommand.Path
       $script = $installPath
       $prm = $script
     foreach($a in $args) {
        $prm += ' ' + $a
     }
        $psi.Arguments = $prm
        $psi.Verb = "runas"
    [System.Diagnostics.Process]::Start($psi) | Out-Null
     return;
    }
  }
  </code></pre>