How do I start PowerShell from Windows Explorer?

前端 未结 19 1430
無奈伤痛
無奈伤痛 2020-12-04 04:24

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\"?

相关标签:
19条回答
  • 2020-12-04 05:12

    For autohotkey users, heres a snippet I am using

    It opens PowerShell window, when pressing Ctrl-Alt-T. (Tested with Win10)

    If your "active window" is a Windows Explorer -window, then the PowerShell is opened in the current folder. Otherwise, just open PowerShell in some default folder.

    Usage: 1) Install AutoHotkey, and copy paste this into myscript.ahk 2) Replace <DefaultPath> with path of your choice. 3) Run the script.

    ; 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
    
    0 讨论(0)
  • 2020-12-04 05:13

    The following is a concise (and updated) summation of the earlier solutions. Here's what to do:

    Add these strings and their respective parent keys:

    pwrshell\(Default) < Open PowerShell Here
    pwrshell\command\(Default) < powershell -NoExit -Command Set-Location -LiteralPath '%V'
    pwrshelladmin\(Default) < Open PowerShell (Admin)
    pwrshelladmin\command\(Default) < powershell -Command Start-Process -verb runAs -ArgumentList '-NoExit','cd','%V' powershell
    

    at these locations

    HKCR\Directory\shell (for folders)
    HKCR\Directory\Background\shell (Explorer window)
    HKCR\Drive\shell (for root drives)
    

    That's it. Add the "Extended" strings for the commands only to be visible if you hold the "Shift" key, everything else is superfluous.

    0 讨论(0)
  • 2020-12-04 05:14

    In Windows 10 both the command prompt and the powershell prompt can be found via the menu bar, for both non-admin and admin. These options will have its folder set to the currently selected folder from the explorer.

    For the Swedish version at least, the powershell is opened with Alt F+I. For an administrator powershell it's Alt F+S+P.

    If those are not the correct characters you can press and hold the Alt key to see the correct characters. there will be a character overlaying the menu item for each step.

    0 讨论(0)
  • 2020-12-04 05:15

    Try the PowerShell PowerToy... It adds a context menu item for Open PowerShell Here.

    Or you could create a shortcut that opens PowerShell with the Start In folder being your Projects folder.

    0 讨论(0)
  • 2020-12-04 05:15

    I created a fully automated solution to add PS and CMD context items. Just run set_registry.cmd and it will update registry to add two buttons when click RMB on folder or inside some opened folder:

    This will change owner of registry keys to admin and add context menus
    Change registry to enable PS and CWD context menus

    0 讨论(0)
  • 2020-12-04 05:16

    You can download the inf file from here - Introducing PowerShell Prompt Here

    0 讨论(0)
提交回复
热议问题