Powershell – Methods of acquiring admin privileges when working with scripts

Here are a few ways to acquire (prompt for) admin privileges when using PowerShell.

1. In-Script (best way IMO, if it ALWAYS needs to run as admin):

NOTE: If execution policy changes are needed, replace the arguments with the following (if erroring out and closing, add “-noexit”):

Sauce

3. Within PowerShell (or another script):

Start-Process "$psHome\powershell.exe" -verb runas -ArgumentList "-file C:\scripts\script.ps1"

…also run any application as admin with this…
Start-Process cmd -verb runas
Start-Process notepad.exe -verb runas

3. With a .lnk file:

  1. Right Click your PowerShell script file and choose Create shortcut
  2. Name it as you like…
  3. Right-click the shortcut and click Properties
  4. Add powershell.exe -file at the beginning of the Target field
  5. Go to the Shortcut tab
  6. Click Advanced
  7. Check the Run as Administrator box
  8. Click OK
  9. Profit.