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?
|
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? |
|||
|
|
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.
You can now run the script elevated by simple double-clicking the new shortcut on your desktop. |
|||||||||
|
|
if you are in the same powershell you could do this:
|
|||
|
|
|
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 Or, you could apply |
||||
|
|
|
You can run PowerShell scripts in Windows 7 using powershell_ise. Step by step instruction can be found here. |
||||
|
|
|
On UAC-enabled systems, to make sure a script is running with full admin privileges, add this code at the beginning of your script:
when running your script with the -elevated switch, it will attempt to elevate privileges before running. |
|||
|
|