On my Windows 7 Desktop, I have script.ps1, which needs admin privileges (it starts a service). I want to click on this script and run it with admin privileges.

What's the easiest way to accomplish this?

link|improve this question

62% accept rate
+1 for the question – r0ca Feb 12 '10 at 22:14
feedback

4 Answers

up vote 5 down vote accepted

Here is one way of doing it, with the help of an additional icon on your desktop. I guess you could move the script someone else if you wanted to only have a single icon on your desktop.

  1. Create a shortcut to your Powershell script on your desktop
  2. Right-click the shortcut and click Properties
  3. Click the Shortcut tab
  4. Click Advanced
  5. Select Run as Administrator

You can now run the script elevated by simple double-clicking the new shortcut on your desktop.

link|improve this answer
feedback

Since it's sitting onto your desktop, I'd say the most effortless way to get this done is dragging it onto the elevation gadget.

Otherwise you could make a separate script using the elevate command on your ps1 script.

Or, you could apply elevate just to the service-starting bit.

link|improve this answer
I'm not a fan of PS but I need to get into it... Good answer badp! – r0ca Feb 12 '10 at 22:13
feedback

if you are in the same powershell you could do this:

Start-Process powershell -verb runas -ArgumentList "-file fullpathofthescript"
link|improve this answer
feedback

You can run PowerShell scripts in Windows 7 using powershell_ise.

Step by step instruction can be found here.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.