Run Script or Command as Admin in Powershell

A coworker of mine was writing a script to simplify some configuration items on some servers, and he ran into a snag.  If you’ve worked in IT for at least a day, you’ve seen this message at some point:

Access denied error, seen here in its natural habitat.

 

 

 

 

This is easily solved using the old right-click -> Run as Administrator routine, but what if you need a script to run a command, or an entire script as administrator?  In this post I go through the three scenarios I’ve come across for running some Powershell commands as an administrator; a single command, an entire .ps1 or batch file, and a entire script from within the script calling it.

Continue reading