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 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)
Windows 10 made it much easier. You can either:
Open PowerShell window here
.Or you can:
File
-> Open Windows PowerShell
.And for a bonus ...
If you right click on File
-> Open Windows PowerShell
, then you can Add to Quick Access Toolbar
:
Which puts a handy icon here:
And now you can just click that icon. :)
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
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.
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.
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'"