Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Invoke-Admin {
  2.     param (
  3.         [string]$program = $(throw "Please specify a program" ),
  4.         [string]$argumentString = "",
  5.         [switch]$waitForExit
  6.     )
  7.  
  8.     $psi = new-object "Diagnostics.ProcessStartInfo"
  9.     $psi.FileName = $program
  10.     $psi.Arguments = $argumentString
  11.     $psi.Verb = "runas"
  12.     $psi.RedirectStandardOutput = $true
  13.     $psi.UseShellExecute = $false
  14.     $proc = [Diagnostics.Process]::Start($psi)
  15.     $reader = $proc.StandardOutput
  16.     $output = $reader.ReadToEnd()
  17.        
  18.     if ( $waitForExit ) {
  19.         $proc.WaitForExit()
  20.     }
  21.     return $output
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement