Tom Squires
Tom Squires

Reputation: 9296

Force a PowerShell script to be run as administrator

I have written a powershell script that installs and starts some services. It will only work if the script is run as administrator. Is there any way force a script to have those privileges?

Upvotes: 6

Views: 31272

Answers (2)

JPBlanc
JPBlanc

Reputation: 72680

In the case you are using PowerShell V2 You can also do the following :

Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList '-command "Get-Service"'

This would run "Get-Service" as administrator, you can replace it with your script.

Upvotes: 11

Matthew Brubaker
Matthew Brubaker

Reputation: 3117

You might look at the answer to this question. It allows you to force something to be run as another account.

Upvotes: 0

Related Questions