Running Commands Elevated

by Sep 27, 2010

You can launch a separate PS environment and elevate it Iif you are running your script in a restricted environment and want to run a specificparticular command with fully elevated privileges:, you can launch a separate PS environment and elevate it:

Start-Process powershell.exe -argumentlist '-command new-eventlog -logname application -source MyScripts' -verb runas

This will start a temporary elevated PS environment and then registers a new event source in your Application event log, for which you will need full Admin privileges. Next, you can use this new source as a regular user to log messages:

Write-EventLog -logname application -source MyScripts -message "Hello" -entrytype information -EventId 1234

Twitter This Tip! ReTweet this Tip!