Wednesday, October 28, 2015

How to create a self-elevating PowerShell script that will run as administrator every time

Often there are various build processes or other automated tasks that run via PowerShell and need to be run as administrator.  If you forget to run it as administrator, it won't work, and you don't always know.

I came across a great blog post by Ben Armstrong that I have to share, where he's created a block of code you just prefix to the beginning of your PowerShell script that will re-launch it as administrator if it is not.  Check his post out here:

Here's a screenshot of the PowerShell code in case his blog goes down:

1 comment:

  1. I really have no words to thank you because i was having this assignment and was worried where to start. But you really have helped me.