Running Commands Elevated

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!


Posted Sep 27 2010, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.