How do I start PowerShell from Windows Explorer?

前端 未结 19 1474
無奈伤痛
無奈伤痛 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:19

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

    You can download detail script from how to start PowerShell from Windows Explorer

提交回复
热议问题