有没有办法从Windows资源管理器启动PowerShell在一个特定的文件夹,例如右键单击一个文件夹,并有一个选项,如“打开PowerShell在这个文件夹”?

每天我第一次运行MSBuild时,都要更改项目文件夹的目录,这真的很烦人。


当前回答

只有在Windows 10上我才用得到……

创建一个名为PowershellHereContextMenu的文件。reg与下面的内容,右键单击它,并“合并”。

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'"

其他回答

一个相当简单的替代方法是通过快捷方式调用PowerShell。有一个标记为“Start in”的快捷方式属性,它表示在调用快捷方式时使用哪个目录(文件夹)。

如果“起始位置”框为空,则表示使用当前目录。

当您第一次以通常的方式创建PowerShell的快捷方式时,start in框指定了主目录。如果你清空start in框,你现在有一个powershell的快捷方式,在当前目录下打开PS,不管那是什么。

如果现在将该快捷方式复制到目标目录,并使用资源管理器调用它,那么将启动指向目标目录的PS。

这个问题已经有了一个公认的答案,但我提供了另一种方式。

在Windows 8.1和Server 2012 R2中更容易。

这样做一次: 右键单击任务栏,选择“属性”。在导航选项卡中,当我右键单击左下角或按Windows键+X时,打开菜单中的[✓]将命令提示符替换为Windows PowerShell。

然后当你想要PowerShell提示时,点击Win+X, i(或Win+X, a表示Admin PowerShell提示)

对于自动热键用户,这里有一个片段我正在使用

当按Ctrl-Alt-T时,它会打开PowerShell窗口。(Win10测试)

如果您的“活动窗口”是Windows资源管理器窗口,那么PowerShell将在当前文件夹中打开。否则,只需在某个默认文件夹中打开PowerShell。

使用方法:1)安装AutoHotkey,复制粘贴到myscript。2)将<DefaultPath>替换为您选择的路径。3)运行脚本。

; 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

有一个Windows资源管理器扩展是由一个为SVN制作工具的家伙做的,它至少会打开一个命令提示窗口。

我还没有尝试过,所以我不知道它是否能做PowerShell,但我想与Stack Overflow的兄弟们分享我的爱:

http://tools.tortoisesvn.net/StExBar

在最新版本的Windows 10中,当你用鼠标Shift+右键点击空白区域时,默认在上下文菜单中有“在此打开PowerShell窗口”,现在你应该已经在使用Windows终端了。