Elevate Powershell scripts

前端 未结 5 1374
深忆病人
深忆病人 2020-12-13 22:38

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

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 23:07

    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.

提交回复
热议问题