Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Invoke-Admin {
- param (
- [string]$program = $(throw "Please specify a program" ),
- [string]$argumentString = "",
- [switch]$waitForExit
- )
- $psi = new-object "Diagnostics.ProcessStartInfo"
- $psi.FileName = $program
- $psi.Arguments = $argumentString
- $psi.Verb = "runas"
- $psi.RedirectStandardOutput = $true
- $psi.UseShellExecute = $false
- $proc = [Diagnostics.Process]::Start($psi)
- $reader = $proc.StandardOutput
- $output = $reader.ReadToEnd()
- if ( $waitForExit ) {
- $proc.WaitForExit()
- }
- return $output
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement