Sagun
Sagun

Reputation: 71

How do run a powershell script as an admin?

I have the silent uninstall/wait/install script below that I need to push out to users, but I need to script it so it runs as administrator and I found some scripts, but I'm not understanding how to script it, any help is appreciated. Also, do I have to put the administrator script in twice? (i.e. in the first line of the uninstall script then before the line of the 2nd install script) or just once when I run it?

Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -eq "On-Screen Takeoff"} | foreach-

object -process {$_.Uninstall()}

Start-Sleep -Seconds 25

$arguments="/quiet"

Start-Process "\\davisconstruction.com\ROOT\Installs\OnCenter\OST\Testverion3906\ost3906.msi" $arguments

Upvotes: 3

Views: 42828

Answers (1)

lkhudisman
lkhudisman

Reputation: 109

There are two ways:

  1. You can right-click on "Start" --> "Windows PowerShell Module" or "Windows PowerShell ISE" by going to "Start" --> "Administrative Tools" --> "Windows PowerShell Module" or "Windows PowerShell ISE". Select "Run As administrator". Anything you run in that window will be as "Administrator".

  2. Run your script as:

    Start-Process "$psHome\powershell.exe" -verb runas -ArgumentList "-file fullpathofthescript"

Upvotes: 5

Related Questions