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

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


当前回答

要以管理员身份在文件资源管理器的任何位置运行PowerShell,请到该文件夹,并使用快捷方式“alt + f + s + a”以管理员身份在该特定文件夹位置打开PowerShell

其他回答

我想让这个上下文菜单只在右键单击并按住“SHIFT”时工作,这是内置的“在这里打开命令窗口”上下文菜单的工作方式。

然而,所提供的解决方案都没有做到这一点,所以我不得不滚动我自己的.reg文件-复制下面的文件,将其保存为power-shell-here-on-shift。Reg并双击它。

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

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

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

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

通过添加下面的注册表键,在Windows 10中,我成功地在我的SHIFT + RClick上下文菜单中获得了Open PowerShell Here选项。 只需将这些复制到一个空白的记事本文件中,然后保存为.reg文件,并运行该文件来添加密钥,它应该从那里开始工作。 其中一些其他答案说,将密钥添加到HKCR\Directory\shell,但我发现,对我来说,它只适用于进入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'"

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

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

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

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

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

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

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