28 February 2013

I searched far and wide over the internet looking for an easy way to elevate powershell in a script whenever I needed to.  The only solutions I ever found were practically a full page of code to look at this, and check that, then do this, jump through this hoop so it could do that… It had to be simpler than that!  I didn’t even attempt to use their solutions because I refused to accept it’s complicated code.

It happens with start-process.  The parameters are picky in how they are used but once you straighten it out in your head (or through many different trial and error iterations like myself) it’s not too bad.  You can eleveate from within powershell, from a command prompt, or from a shortcut.

From Powershell:

start-process powershell.exe -verb runAs

Or if you want to run a command:

start-process powershell “get-process” -verb runAs
Anything passed in the quotes after the process name is passed as an argument to powershell (kind of like a script block)

You can also pass the path to a script as the argument.

From the Command Line

powershell.exe “start-process powershell -verb runAs”
Same thing as in powershell except you start a normal shell and execute a command to open an elevated shell right off the bat.

From a Shortcut

Your target should be:  C:\path-to-powershell\powershell.exe “optional script file path” -verb runAs

And that’s all there is to it.  Now, if you have UAC turned on you will be prompted.  At work I don’t have this problem because we have a man-in-the-middle software that injects the token that allows the elevation without a UAC prompt.


There are no comments.



You must be logged in to post a comment.

Links

RSS 2.0 Feed

Support

Brave Rewards
This site supports Brave Rewards. Please consider tipping or adding it to your monthly contributions if you find anything helpful!

For other ways: Support

Support this blog! If you have found it helpfu you can send me crypto. Any amount is appreciated!
ETH: 0xBEaF72807Cb5f4a8CCE23A5E7949041f62e8F8f0 | BTC: 3HTK5VJWr3vnftxbrcWAszLkRTrx9s5KzZ | SHIB: 0xdb209f96dD1BdcC12f03FdDfFAD0602276fb29BE
Brave Users you can send me BAT using the browser.