298

Is there a way to start PowerShell in a specific folder from Windows Explorer, e.g. to right-click in a folder and have an option like "Open PowerShell in this Folder"?

It's really annoying to have to change directories to my project folder the first time I run MSBuild every day.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Josh Kodroff
  • 27,301
  • 27
  • 95
  • 148

22 Answers22

572

In Windows Explorer, just go to the Address Bar at the top (keyboard shortcuts: Alt+D or Ctrl+L) and type powershell or powershell_ise and press Enter. A PowerShell command window opens with the current directory.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ashwin Nanjappa
  • 76,204
  • 83
  • 211
  • 292
  • 7
    When I do this on Win 7, Windows Explorer takes me to a folder I have that is named PowerShell! – Sabuncu May 20 '13 at 08:45
  • 44
    If you're on Windows 8, or later, you can simply use the built-in File -> "Open Windows Powershell" – V Maharajh Jun 25 '13 at 09:04
  • 1
    Unfortunately, this doesn't work if directory you are in contains a directory named "Powershell" :( – nlowe May 08 '14 at 13:38
  • 7
    It also doesn't work if you have a PowerShell profile that sets the startup directory. If you want to startup without the profile you can use "powershell -noprofile", but then you lose whatever settings you have in the profile. There's always a trade off. – grahamesd May 28 '14 at 13:07
  • 10
    any shortcut to open it up as administrator? – Arsalan Ahmad Sep 07 '14 at 12:31
  • 3
    Instead of powershell you could also type powershell_ise which is nicer since it is finally resizable and has a proper font. – Michael S. Feb 14 '15 at 10:38
  • It does not work me. It opens up internet explorer with the powershell as url. Any ideas how to activate it? – user3586195 Jun 01 '15 at 17:06
  • @ArsalanDotMe- setting it up once by going to PS Properties - Advanced- Run as administrator, will always open you PS with administrator rights. – Iqra. Feb 08 '18 at 06:42
  • 2
    @ArsalanDotMe You can do "Alt, F, S, A" as a sequence on Windows 10. It is as if you were clicking File, then the arrow on "Open Windows PowerShell" and selecting "Open Windows PowerShell as administrator" – juanferrer May 24 '18 at 06:25
  • Anybody nows why I get different PATH for my applications when I launch it like this compared to just launching the "Windows PowerShell" app? See https://stackoverflow.com/questions/51409878/why-is-there-a-path-difference-depending-on-how-you-open-powershell – Gandalf Saxe Jul 18 '18 at 19:45
  • Oddly, I just re-installed Windows 10 on an old laptop and when I type `powershell` in the file menu it takes me to `C:\Users\{username_redacted}\OneDrive\Documents\PowerShell` which is a folder I could delete and maybe make the issue go away - typing `powershell_ise` opens that up just fine. On all of my other machines, typing `powershell` in the File Explorer address bar just opens PowerShell as others have described. – Bleak Morn Dec 17 '21 at 20:19
119

Just to add in the reverse as a trick, at a PowerShell prompt you can do:

ii .

or

start .

to open a Windows Explorer window in your current directory.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
EBGreen
  • 36,735
  • 12
  • 65
  • 85
95

If you're on Windows 8, or later, you can simply use the built-in File → "Open Windows PowerShell".

Or Alt + F followed by R.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
V Maharajh
  • 9,013
  • 5
  • 30
  • 31
50

As an alternative to the answer above, which requires you to type the PowerShell command (powershell.exe) each time, you can create a context menu entry just like with the "Open command window here" context menu.

There are three registry keys where these commands go. Each key controls the context menu of a different Windows Explorer object. The first one is the one you asked about:

  • HKCR\Directory\Background\shell - This is the context menu for the Explorer window itself (that is, the context menu that is displayed when no item is selected, such as when right-clicking in an empty area of the window).
  • HKCR\Directory\shell - This is the context menu of the folders in Windows Explorer.
  • HKCR\Drive\shell - This is the context menu for the drive icons in the root of Windows Explorer.

For each of these registry keys, you can add a subkey that will add an "Open PowerShell window here" command to the context menu, just as you have an "Open command window here" context menu.

Here is a copy of my OpenPowerShellHere.reg file, which puts the command in the context menu of each of the Explorer objects, the window background, the folder, and the drive icon:

Windows Registry Editor Version 5.00

;
; Add context menu entry to Windows Explorer background
;
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell]
@="Open PowerShell window here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

;
; Add context menu entry to Windows Explorer folders
;
[HKEY_CLASSES_ROOT\Directory\shell\powershell]
@="Open PowerShell window here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\shell\powershell\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

;
; Add context menu entry to Windows Explorer drive icons
;
[HKEY_CLASSES_ROOT\Drive\shell\powershell]
@="Open PowerShell window here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Drive\shell\powershell\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

So, with your favorite text editor, open a new file named OpenPowerShellHere.reg. Copy the exact text of the code above, paste it into the new file, and save it. (I would have included a copy of the file, but I couldn't figure out if attachments were possible.) If you want to exclude the command from one of the entry, just comment out the appropriate section with semicolons. My comments show you each section.

After you save the file, run it by double-clicking on it. When it asks, tell it to proceed. As soon as you run it, the context menu entries will show up!

Here is my Explorer window context menu. I've highlighted the console and PowerShell commands. As you can see, you can also add a context menu entry to run an elevated command window, i.e., Run as Administrator.

PowerShell entry in Explorer context menu

Note: Context menu entries are displayed alphabetically, based on their Registry keys. The key name for the elevated command shell is "runas", which is why it comes after the PowerShell entry.

Note: If you have an explorer window open, you may need to close it and reopen it to get the changed to take effect.

Note: In Windows 7, the HKCR\Directory\Shell does not work if you use the toolkit on the side of the explorer

(ie. Clicking Documents under the Libraries header)

you must navigate using Computer -> C: -> to -> Some -> Target -> Directory

iggy12345
  • 1,233
  • 12
  • 31
geo
  • 271
  • 5
  • 5
  • One problem here, is when I open a PS Window using this context menu, and enter `git help `, it dumps the html help file in the PS window as plain text. When I use the start menu, that PS window opens the browser like it's supposed to. – ProfK Mar 09 '15 at 22:29
  • @ProfK, I'm not sure what's going on there, since I don't use 'git', however, the PS window that opens using this context menu is IDENTICAL to the PS window that opens using the Start Menu, UNLESS you are using PowerShell ISE when you run it from the Start Menu. If that's the case, you can change "powershell.exe" in the above registry file to "powershell_ise.exe". If you're running the regular PowerShell, then there's no difference, other than the directory in which they start. The Start Menu command starts in your user directory, whereas the context menu starts in the local directory. – geo Mar 11 '15 at 01:07
  • @ProfK, Is it possible that it's the starting directory that's making the difference? If you have something in your user directory concerning 'git', maybe that's the difference. The whole purpose of the context menu is to open PS in the LOCAL directory, but if the 'git' command runs differently based on the directory you're in, that could be the problem. The directory difference and the difference between PS and PS ISE are the only things I can think of. – geo Mar 11 '15 at 01:10
  • @geo Thanks for all the feedback, but I found that double clicking html files in Explorer was opening them in Notepad++. I set my default "Open with" to Chrome, but I also installed Posh-Git at the same time, and now my Git help opens in Chrome, not PS. Sad side is I don't know which changed fixed things. – ProfK Mar 11 '15 at 05:37
  • 1
    PS script to add elevated PS prompt (remove the HasLUAShield line for non-elevated) is @ http://www.powershellmagazine.com/2013/06/25/pstip-how-to-start-an-elevated-powershell-from-windows-explorer/ – James Manning Nov 21 '15 at 21:52
  • @ProfK Sadly, the way Windows handles which program opens what file is confusing. That's because there's more than one location where it's defined. The registry entries I showed you are where the system keeps its information. New programs can change those definitions without telling you, but they're still in the same location. However, when you use the "Open with" menu in Windows Explorer, that information is stored in a different location! This is done so that different users can assign different programs. Therefore, "Open with" overrides the system's definition in favor of yours. – geo Feb 29 '16 at 00:09
  • added step by step details in this article https://developingdaily.com/article/how-to/how-to-add-or-remove-open-powershell-here-to-context-menu/277 – Vikas Lalwani Jul 04 '22 at 08:25
  • Using @="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'" will cause problems, if %V expands to a string containing any apostrophe/single quote (') characters, and PowerShell 5.1 itself offers no reliable way to remedy this. A better way to do it is to invoke PowerShell using 'cmd /c start', i.e.: @="\"C:\\Windows\\System32\\cmd.exe\" /c start \"Windows PowerShell\" /d \"%V\\.\" \"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -NoExit" – R.G. Jun 29 '23 at 20:55
33

You can download the inf file from here - Introducing PowerShell Prompt Here

Gulzar Nazim
  • 51,744
  • 26
  • 128
  • 170
16

I'm surprised nobody has given this answer, it's the simplest one. (Must be the year.)

Just Shift + right click in Explorer. Then you can "Open PowerShell window here".

It may be set to Command Prompt by default. If so, you can change this in the Windows 10 Settings: go to Personalization -> Taskbar and enable "Replace Command Prompt with Windows PowerShell in the menu when I right-click the start button or press Windows key+X".

Andrew
  • 5,839
  • 1
  • 51
  • 72
15

In Windows 10 both the command prompt and the powershell prompt can be found via the menu bar, for both non-admin and admin. These options will have its folder set to the currently selected folder from the explorer.

For the Swedish version at least, the powershell is opened with Alt F+I. For an administrator powershell it's Alt F+S+P.

Windows Powershell menu

If those are not the correct characters you can press and hold the Alt key to see the correct characters. there will be a character overlaying the menu item for each step.

default
  • 11,485
  • 9
  • 66
  • 102
14

Windows 10 made it much easier. You can either:

  • SHIFT + Mouse Right Click on a folder, and you get a menu item Open PowerShell window here.

Or you can:

  • File -> Open Windows PowerShell.

And for a bonus ...

If you Mouse Right Click on File -> Open Windows PowerShell, then you can Add to Quick Access Toolbar:

enter image description here

Which puts a handy icon here:

enter image description here

And now you can just click that icon. :)

Craigo
  • 3,384
  • 30
  • 22
7

I wanted to have this context menu work only when right clicking and holding the 'SHIFT' which is how the built in 'Open Command window here' context menu works.

However none of the provided solutions did that so I had to roll my own .reg file - copy the below, save it as power-shell-here-on-shift.reg and double click on it.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\powershell]
@="Open PowerShell here"
"NoWorkingDirectory"=""
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\shell\powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"

open power shell here while holding shift and pressing right click

James Manning
  • 13,429
  • 2
  • 40
  • 64
Daniel Sokolowski
  • 11,982
  • 4
  • 69
  • 55
5

Try the PowerShell PowerToy... It adds a context menu item for Open PowerShell Here.

Or you could create a shortcut that opens PowerShell with the Start In folder being your Projects folder.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Steven Murawski
  • 10,959
  • 41
  • 53
4

In the more recent versions, Windows 10 has "Open PowerShell window here" by default in the context menu when you Shift+Mouse Right Click on an empty space, and you should be using Windows Terminal by now anyway.

ppw0
  • 343
  • 3
  • 11
3

It's even easier in Windows 8.1 and Server 2012 R2.

Do this once: Right-click on the task bar, choose Properties. In the Navigation tab, turn on [✓] Replace Command Prompt with Windows PowerShell in the menu when I right-click the lower-left corner or press Windows key+X.

Then whenever you want a PowerShell prompt, hit Win+X, I. (Or Win+X, A for an Admin PowerShell prompt)

Warren Rumak
  • 3,824
  • 22
  • 30
3

There's a Windows Explorer extension made by the dude who makes tools for SVN that will at least open a command prompt window.

I haven't tried it yet, so I don't know if it'll do PowerShell, but I wanted to share the love with my Stack Overflow brethren:

http://tools.tortoisesvn.net/StExBar

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Josh Kodroff
  • 27,301
  • 27
  • 95
  • 148
2

Another option are the excellent Elevation PowerToys by Michael Murgolo on TechNet at http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx.

They include PowerShell Prompt Here and PowerShell Prompt Here as Administrator.

Mark Larson
  • 499
  • 3
  • 13
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Lundin Apr 24 '14 at 11:56
  • That is a valid point to consider when posting a link; however, the linked article contains the authoritative download to the Elevation PowerToys, which _is_ the essential part of the answer. – Mark Larson Apr 24 '14 at 17:25
2

By adding the registry keys below, in Windows 10, I managed to get the Open PowerShell Here option in my SHIFT + RClick context menus. Just copy these into a blank notepad file then save as a .reg file and run the file to add the key and it should work from there. Some of these other answers say to add the key into HKCR\Directory\shell but I found that for me it only worked with the keys going into HKLM\SOFTWARE\Classes\Directory\shell

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\powershell]
"Extended"=""
"NoWorkingDirectory"=""
@="Open PowerShell here"
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\powershell]
@="Open PowerShell here"
"Extended"=""
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
"NoWorkingDirectory"=""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
Rhys
  • 132
  • 8
1

One fairly simple alternative is to invoke PowerShell via a shortcut. There is a shortcut property labeled "Start in" that says what directory(folder) to use when the shortcut is invoked.

If the Start In box is blank, it means use the current directory.

When you first create a shortcut to PowerShell in the usual way, the start in box specifies the home directory. If you blank out the start in box, you now have a shortcut to powershell that opens PS in the current directory, whatever that is.

If you now copy this shortcut to the target directory, and use explorer to invoke it, you'll start a PS that's pointed at the target directory.

There's already an accepted answer to this question, but I offer this as another way.

Walter Mitty
  • 18,205
  • 2
  • 28
  • 58
1
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
if(-not (Test-Path -Path "HKCR:\Directory\shell\$KeyName"))
{
    Try
    {
        New-Item -itemType String "HKCR:\Directory\shell\$KeyName" -value "Open PowerShell in this Folder" -ErrorAction Stop
        New-Item -itemType String "HKCR:\Directory\shell\$KeyName\command" -value "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command Set-Location '%V'" -ErrorAction Stop
        Write-Host "Successfully!"
     }
     Catch
     {
         Write-Error $_.Exception.Message
     }
}
else
{
    Write-Warning "The specified key name already exists. Type another name and try again."
}

You can download detail script from how to start PowerShell from Windows Explorer

frank tan
  • 131
  • 1
  • 4
1

For autohotkey users, heres a snippet I am using

It opens PowerShell window, when pressing Ctrl-Alt-T. (Tested with Win10)

If your "active window" is a Windows Explorer -window, then the PowerShell is opened in the current folder. Otherwise, just open PowerShell in some default folder.

Usage: 1) Install AutoHotkey, and copy paste this into myscript.ahk 2) Replace <DefaultPath> with path of your choice. 3) Run the script.

; Ctrl-Alt-T opens PowerShell in the current folder, if using Windows Explorer. Otherwise, just open the Powershell.
^!T::
if WinActive("ahk_class CabinetWClass") and WinActive("ahk_exe explorer.exe")
{
    KeyWait Control
    KeyWait Alt
    Send {Ctrl down}l{Ctrl up}
    Send powershell{Enter}
}
else
{
    psScript =
    (
    cd 'C:\<DefaultPath>'
    ls
    )
    Run "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" -NoExit -Command &{%psScript%}
}
return
Niko Föhr
  • 28,336
  • 10
  • 93
  • 96
1

I created a fully automated solution to add PS and CMD context items. Just run set_registry.cmd and it will update registry to add two buttons when click RMB on folder or inside some opened folder: enter image description here

This will change owner of registry keys to admin and add context menus
Change registry to enable PS and CWD context menus

Beliaev Maksim
  • 968
  • 12
  • 21
1

Only this worked for me on Windows 10...

Create a file named PowershellHereContextMenu.reg with the contents below, right click on it and "Merge".

Windows Registry Editor Version 5.00

;
; Add context menu entry to Windows Explorer folders
;
[HKEY_CLASSES_ROOT\Directory\shell\powershellmenu]
@="PowerShell Here"

[HKEY_CLASSES_ROOT\Directory\shell\powershellmenu\command]
@="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"

;
; Add context menu entry to Windows Explorer background
;
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershellmenu]
@="PowerShell Here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\powershellmenu\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

;
; Add context menu entry to Windows Explorer drive icons
;
[HKEY_CLASSES_ROOT\Drive\shell\powershellmenu]
@="PowerShell Here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Drive\shell\powershellmenu\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

Timothy
  • 4,198
  • 6
  • 49
  • 59
0

to run PowerShell as an admin in any location of file explorer go to that folder and use the shortcut "alt + f + s + a" to open powershell as an admin in that specific folder location

Jai advith
  • 614
  • 3
  • 5
0

You can run the below command on the Windows Explorer address bar to open powershell , and it will open the path to this directory.

powershell.exe -noexit -command "Write-Host "Hello World""

sudhansu63
  • 6,025
  • 4
  • 39
  • 52