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

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


当前回答

我很惊讶没有人给出这个答案,这是最简单的答案。(一定是那年。)

只需在资源管理器中Shift +右键单击。然后你可以在这里打开PowerShell窗口。

默认情况下可以设置为命令提示符。如果是这样,你可以在Windows 10设置中进行更改:转到个性化->任务栏,启用“当我右键单击开始按钮或按Windows键+X时,将菜单中的命令提示符替换为Windows PowerShell”。

其他回答

在Windows 10中,命令提示符和powershell提示符都可以通过菜单栏找到,无论是非管理员用户还是管理员用户。这些选项将其文件夹设置为当前从资源管理器中选择的文件夹。

至少对于瑞典版本,powershell是用Alt F+I打开的。对于管理员powershell,它是Alt F+S+P。

如果这些不是正确的字符,您可以按住Alt键查看正确的字符。每个步骤的菜单项上将覆盖一个字符。

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

当按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

另一个选择是Michael Murgolo在TechNet网站http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx上推出的Elevation PowerToys。

它们包括PowerShell提示符在这里和PowerShell提示符在这里作为管理员。

只有在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'"

在Windows资源管理器中,只需转到顶部的地址栏(键盘快捷键:Alt+D或Ctrl+L),输入powershell或powershell_ise并按Enter。将打开一个PowerShell命令窗口,其中包含当前目录。