Showing the UAC prompt in PowerShell if the action requires elevation

前端 未结 3 2016
轻奢々
轻奢々 2020-12-08 16:48

I have a simple PowerShell script to stop a process:

$p = get-process $args
if ( $p -ne $null )
{
$p | stop-process
$p | select ProcessName, ID, HasExited, C         


        
3条回答
  •  独厮守ぢ
    2020-12-08 17:02

    First install PowerShell Community Extensions choco install pscx via Chocolatey (you may have to restart your shell environment)

    then enable pscx

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser #allows scripts to run from the interwebs, such as pcsx
    

    Then use Invoke-Elevated, for example

    Invoke-Elevated {Add-PathVariable $args[0] -Target Machine} -ArgumentList $MY_NEW_DIR
    

提交回复
热议问题