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

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


当前回答

尝试PowerShell PowerToy…它为Open PowerShell Here添加了一个上下文菜单项。

或者您可以创建一个快捷方式,打开PowerShell的开始文件夹是您的项目文件夹。

其他回答

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."
}

您可以从Windows资源管理器中下载如何启动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'"

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

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

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

您可以在Windows资源管理器地址栏上执行以下命令打开powershell,它将打开该目录的路径。

powershell.exe -noexit -command "Write-Host "Hello World"