6

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?

Sam
  • 15,336
  • 25
  • 85
  • 148
Tom Squires
  • 8,848
  • 12
  • 46
  • 72
  • http://stackoverflow.com/questions/1566969/showing-the-uac-prompt-in-powershell-if-the-action-requires-elevation – dugas Oct 05 '12 at 15:39

2 Answers2

11

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.

JPBlanc
  • 70,406
  • 17
  • 130
  • 175
0

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

Community
  • 1
  • 1
Matthew Brubaker
  • 3,097
  • 1
  • 21
  • 18