PowerShell Script that Relaunches as Admin
If were following good security practices we run our Windows system with UAC enabled. This means that if you forget to launch your PowerShell prompt as Administrator when you run a script that requires administrative privilege then that script will fail. It would be nice to build a mechanism into our script to “auto-elevate” if UAC is enabled. The trick to doing this is to run Start-Process ““verb runas. After that you only need to figure out if the current user is an administrator and if UAC is enabled.