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?
Asked
Active
Viewed 2.8k times
6
-
http://stackoverflow.com/questions/1566969/showing-the-uac-prompt-in-powershell-if-the-action-requires-elevation – dugas Oct 05 '12 at 15:39
2 Answers
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
- 67,114
- 13
- 128
- 165
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,077
- 1
- 20
- 18