.NET Framework - run powershell always as admin ?

Asked By Robert Ludig on 25-Feb-07 07:00 AM
A lot of powershell related tasks and commands require elevated right.
How can I either

a) run the powershell always as administrator
b) temporarily elevate the rights

I suppose a) is a nono ? :)

Rich replied on 25-Feb-07 10:32 AM
If you are talking about running on Vista you can right click icon & run as
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
Robert Ludig replied on 26-Feb-07 05:58 AM
Is there a way to create a shortcut or link that has "run as
administrator" applied automatically? So that I do not have to bother
to rightclick and can use keyboardhortucts to run the powershell?

Also, is it safe to always runt the whole shell elevated?

Is there a way to temporarily elevate the rights for specific tasks/
commands? It seems I don't get the UAC promt when trying to execute
commads that need elevated rights and the shell is not run as
administrator. Instead I just get a permission error.
Daymo replied on 26-Feb-07 02:10 PM
In XP (or Vista), just create a standard shortcut to the powershell exe.

Then in the properties of the shortcut, click the advanced button and check
the run with different credentials.

Now when you dbl-clk the shortcut, windows brings up the run-as dialog for
Robert Ludig replied on 27-Feb-07 02:32 AM
This approach would still require me to enter the password for the
admin account each time I run the shell. Wich is a bit annoying when
using the shell frequently. Also what happens when I doubleclick .ps1
files (wich starts the powershell), the executing script does not have
elevated rights ...
Joris van Lier replied on 28-Feb-07 07:06 AM
Maybe you can use http://sudowin.sourceforge.net/

Lee Holmes [MSFT] replied on 01-Mar-07 12:43 PM
In Vista's UAC model, you don't enable your Administrator rights for an
application until you've gone through an elevation prompt. So yes, this
means that you will be required to type in your credentials (or click "OK")
whenever you want to load an elevated program (powershell included.) If
there are aspects of this that frustrate you, then the best bet is to
provide your feedback to the Vista UAC team --
http://blogs.msdn.com/windowsvistasecurity/ may be a good starting point.

As for your second point, double-clicking a script doesn't start PowerShell
unless you've specifically modified your system to enable that. In that
case, you may want to create a right-click menu option to execute the script
using the Elevated PowerShell link that Daymon spoke about.

That said, Michael Murgolo (who wrote "PowerShell Here"
http://www.leeholmes.com/blog/PowerShellPromptHerePowerToy.aspx) will soon
be releasing a little utility pack to make some of these scenarios easier.

In terms of the safety of running PowerShell as administrator -- it's
definitely a best practice to run without Administrator rights whenever
possible. If you're just navigating the filesystem, changing files, running
utility scripts, etc -- then I would advise running those in a regular
PowerShell window. If you need to modify administrative data on the
computer, then by all means perform that action in an elevated window.

Lee Holmes [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

UAC is a core feature of Vista, so