返回列表 发帖

[转载代码] [PowerShell每日技巧]提权执行命令(20140319)

Sometimes, a script may need to run a command that needs elevation (Administrator privileges).

Instead of requiring the script to run with full privileges altogether, you can also send individual commands to an elevated shell.

This will restart the Spooler driver (which requires elevated privileges), and sends the command to another PowerShell process. It will automatically start elevated if the current process does not have Administrator privileges.
$command = 'Restart-Service -Name spooler'
Start-Process -FilePath powershell.exe -ArgumentList "-noprofile -command $Command" `
-Verb runasCOPY
http://powershell.com/cs/blogs/tips/archive/2014/03/19/running-commands-elevated-in-powershell.aspx

返回列表