2

I can use Explorer's "Open PowerShell window here" context menu item to open PowerShell in the current folder. However, this prompt runs as a limited user. How can I elevate this prompt so that it runs as administrator, keeping the current directory?

3
  • You must use an Administrator account in order do this. So enable the built-in Administrator in order to do that.
    – Ramhound
    Oct 6, 2017 at 18:24
  • @Ramhound Yes, I'm Administrator account indeed. But when I start-up Powershell by right mouse, I just enter into the Powershell with a common user.
    – yode
    Oct 6, 2017 at 19:16
  • How are you starting up Powershell? I have a default new Windows 10 install at hand, I right click in an empty folder and I don't see any Powershell contextual items. Oct 6, 2017 at 19:28

1 Answer 1

10

Unfortunately, Windows does not allow the primary token to be replaced after the process starts running. For purposes of this answer, that means that we can't change the user or elevation status under which an existing PowerShell prompt runs.

To prompt for the elevation of a new PowerShell process that starts in the current directory, you can use this command:

Start-Process powershell -Verb runas -ArgumentList "-NoExit -c cd '$pwd'"

The -Verb runas prompts for elevation, while -ArgumentList supplies a command line to the new process. -c gives it a command to run (string interpolation turns $pwd into the current process's current directory). -NoExit tells the new process to not end after it finishes its startup commands.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .