Is it possible to elevate the permissions of a powershell script so a user without admin privileges can run the script? Our network admins are trying to find more time-effi
if you are using V2, you can use the following which is up on the PowerShell Team Blog
Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList '-command "Get-Process"'
This would run "Get-Process" as administrator.
If you don't have V2, you could create a StartInfo object and set the Verb to Runas like this.
function Start-Proc {
param ([string]$exe = $(Throw "An executable must be specified"),[string]$arguments)
# Build Startinfo and set options according to parameters
$startinfo = new-object System.Diagnostics.ProcessStartInfo
$startinfo.FileName = $exe
$startinfo.Arguments = $arguments
$startinfo.verb = "RunAs"
$process = [System.Diagnostics.Process]::Start($startinfo)
}
I have a blog post that talks a bit more about using a System.Diagnostics.ProcessStartInfo object.