40

Is there a way to run a Powershell Prompt with Elevated privileges from a command linein Server 2012?

Problem is this is 'Minimal Server Interface' mode without full server-gui installed so I can run powershell from only either the command prompt or from ServerManager.

I am actually trying to run the command: Enable-ServerManagerStandardUserRemoting but although this appears to work it does not add the user in question to the various groups as it is supposed to do. I suspect it is not working properly because I am not running it from a fully elevated powershell prompt, just a standard prompt but as Administrator.

Thanks, Nick

NickC
  • 2,313
  • 13
  • 40
  • 52

2 Answers2

55

Sure... works on Windows 7+, too.

Open Powershell first:

Type PowerShell to enter a PowerShell session.

Once in the session:

Type Start-Process PowerShell -Verb RunAs and press Enter.

That will open a new Powershell process as Administrator.

------- OR -------

To do it all with only one line from the command prompt, just type:

powershell -Command "Start-Process PowerShell -Verb RunAs"

Nnnes
  • 103
  • 2
TheCleaner
  • 32,352
  • 26
  • 126
  • 188
  • Thanks, that probably worked. Enable-ServerManagerStandardUserRemoting still doesn't add the user to the groups but at least that rules out any lack of elevation problem. – NickC Jan 08 '13 at 16:15
  • I've never messed with that command...but I'm guessing you already looked here for details? http://technet.microsoft.com/library/jj205470 – TheCleaner Jan 08 '13 at 17:14
  • 2
    you can shorten it a bit, and you don't need any caps: `start powershell -verb runas` – joniba May 26 '21 at 15:58
  • This is weird and impossible to remember, probably I need to use an alias to shorten it, but still weird. I expected this to be only a one word command like `sudo` on Linux. Probably because Windows mostly assumes that users will use its GUI based solutions? – aderchox Jun 30 '22 at 18:19
  • 1
    @aderchox - sure, you can easily create a function as part of your local powershell profile and just call it whenever. Most don't need this, if you already have the GUI then launching powershell as administrator is simple enough already. – TheCleaner Jul 05 '22 at 12:38
1

An alternative method is to do the following:

  1. type: runas /user:admin username powershell
  2. enter the appropriate password when prompted

You're done!

Opera512
  • 19
  • 2
  • 2
    if you're going to use `runas.exe`, the first step is unnecessary, just run it from `cmd.exe` – Mathias R. Jessen Feb 18 '15 at 15:08
  • 1
    The difference here is mine was simply to run it elevated, not to run it as a different user. If you try mine out you'll see that you aren't prompted for additional credentials, it simply creates a new elevated shell. Yours is more for running Powershell as someone else. – TheCleaner Feb 18 '15 at 17:28
  • Mathias - thank you for correcting me, I'm by no means an expert! TheCleaner - Please don't misunderstand, your method is very good. I couldn't get it to work in my Core 2012 server setup but I'm sure it was my fault! So this was the alternative method, I'll edit the answer. – Opera512 Feb 18 '15 at 18:39