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.
You must be logged in to post a comment.