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 runas
复制代码 http://powershell.com/cs/blogs/tips/archive/2014/03/19/running-commands-elevated-in-powershell.aspx |