Open PowerShell in a Folder: A Step-by-Step Tutorial

Published:18 January 2021 - 4 min. read

Bill Kindle Image

Bill Kindle

Read more tutorials by Bill Kindle!

Azure Cloud Labs: these FREE, on‑demand Azure Cloud Labs will get you into a real‑world environment and account, walking you through step‑by‑step how to best protect, secure, and recover Azure data.

Have you ever been in Windows File Explorer and just need to quickly open a PowerShell prompt in a folder? Do you want a open powershell window here option or open command window here option? If so, you’re in luck. In this tutorial, you’re going to learn how to open PowerShell in a specific folder when using Windows file explorer.

Prerequisites

If you intend to follow along, be sure you have the following:

  • A Windows 10, Windows Server 2016, or Windows Server 2019 host. This tutorial will use Windows 10.
  • Logged in with a local account in the Administrators group or at least with rights to elevate to administrator, if necessary.

Opening PowerShell via the Address Bar

File Explorer has an element at the top of the window that allows you to run programs just like if you were at a command line. You can invoke PowerShell from this address bar by pressing CTRL. From within File Explorer:

  1. Press and hold the ALT or CTRL key.
  2. Press the D or L key. This places the cursor in the address bar.
  3. Type powershell and press Enter. PowerShell will be opened in the current directory.

If you are logged in as the Administrator, then you will be in an administrative prompt for both PowerShell and Command Prompt.

The animated gif below is what you should see on your screen:

Using ALT+D to open a PowerShell Window.
Using ALT+D to open a PowerShell Window.

Opening PowerShell via the File Menu

Another handy way to open PowerShell in File Explorer is to use the file menu. Using the file menu, you could use the mouse or keyboard shortcut. Pressing ALT allows you to open the file menu. Within File Explorer:

  1. Press and hold the ALT key.
  2. Press the F key. This will open the file menu.
  3. Press the S key. This option will select Open Windows PowerShell and will expand another sub-menu.
  4. Lastly, press the R key. PowerShell will open in the current directory.

If you need to open PowerShell as an administrator, use hit A instead of R.

Related: How to Run PowerShell as Administrator

The animated gif below shows what the process should look like:

Using ALT+F+S+R to open a regular PowerShell window in current directory.
Using ALT+F+S+R to open a regular PowerShell window in current directory.

Holding the ALT key while navigating the context menu will display keys to use to jump through menus. The shortcut keys work in Windows 10, Windows Server 2016, and Windows Server 2019.

Building a Custom PowerShell Context Menu

Now that you have all the shortcut keys in your toolbox, it’s time to dive a little deeper and build a context menu within File Explorer.

A context menu is the menu that you see when you right-click on an item in Windows.

Using a specially placed Windows registry key, you can create a custom context menu item to quickly open a PowerShell window when you right click inside of a folder. Let’s change that.

If you right click within a folder in File Explorer, you’ll see below that there is no context menu entry for opening PowerShell.

No context menu entry for PowerShell.
No context menu entry for PowerShell.

However, if hold SHIFT key and then right click in a folder, you’ll then see the context menu item below.

Context menu option when using SHIFT+Right-Click.
Context menu option when using SHIFT+Right-Click.

Let’s build a custom context menu item that’ll allow you to open a PowerShell window without holding Shift key.

To create a custom context menu item, you must create a few different Windows registry keys and values. These values, when created, will instantly create a custom context menu item.

Below are the following Windows registry keys and values necessary:

PathNameValueNotes
HKCR:\Directory\shell\powershellmenu(Default)Open PowerShell Here
HKCR:\Directory\shell\powershellmenu\command(Default)C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command Set-Location -LiteralPath ‘%L’
HKCR:\Directory\shell\runas(Default)Open PowerShell Here as Administrator
HKCR:\Directory\shell\runasHasLUAShieldThis adds a built-in icon for elevated prompts

To add the custom context menu, you can create the above keys and values manually or you can use a PowerShell script to do the dirty work for you.

Below is a script you can use to quickly create all of the necessary keys and values in one shot.

$Menu = 'Open PowerShell Here'
 $Command = "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"
 $RunAsMenu = 'Open PowerShell Here as Administrator'
 HKCR doesn't exist by defualt in PSDrives, so you need to create it.
 New-PSDrive -PSProvider Registry -Root HKEY_CLASSES_ROOT -Name HKCR
 Now create the keys and values (non-admin)
 New-Item -Path HKCR:\Directory\shell -Name 'powershellmenu' -Force |
     Set-ItemProperty -Name '(Default)' -Value $Menu
 New-Item -Path HKCR:\Directory\shell\powershellmenu\command -Force |
     Set-ItemProperty -Name '(Default)' -Value $Command
 Now create the keys and values (admin)
 New-Item -Path HKCR:\Directory\shell -Name 'runas' -Force |
     Set-ItemProperty -Name '(Default)' -Value $RunAsMenu
     # This adds a built-in icon for elevated prompts
     New-ItemProperty -Path HKCR:\Directory\shell\runas\ -Name HasLUAShield -Value ''
 New-Item -Path HKCR:\Directory\shell\runas\command -Force |
     Set-ItemProperty -Name '(Default)' -Value $Command

When you’ve finished creating the registry keys and values, you should see a value that looks like below:

Complete context menu registry key entry for open powershell here option.
Complete context menu registry key entry for open powershell here option.

Testing Out the PowerShell Custom Menu Item

Once complete, close the Windows registry editor if you have it open and right click on any folder within File Explorer. You should now see the new Open PowerShell Here context menu entry you created!

Open PowerShell Here context menu
Open PowerShell Here context menu

Below is the new context menu Open PowerShell Here option in action:

Context menu Open PowerShell Here option in action.
Context menu Open PowerShell Here option in action.

Next Steps

Now that you know all the ways to open a PowerShell window within File Explorer, what else can you add to your context menus to increase your file explorer productivity? Maybe you can add a Open Command Prompt Here or experiment with opening different PowerShell profiles using context menus. Try adding an icon to the context menu even!

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

Explore ATA Guidebooks

Looks like you're offline!