Open Powershell in a specific directory from short

2020-05-13 06:07发布

This sounds like it should be so simple... I must be dumb.

All I want is to make a windows short-cut that opens Powershell into a specific directory:

I'm using the target:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe 
    -noexit -command {cd c:/path/to/open}

Put it just spits out the command as text.

8条回答
Anthone
2楼-- · 2020-05-13 06:54

If one wants a explorer right click options run this script:

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

This is what is shown now:

enter image description here


Note that you can download a detailed script from how to start PowerShell from Windows Explorer.

查看更多
狗以群分
3楼-- · 2020-05-13 06:56

Define a Shortcut for Powershell, and Open the properties of that, and finally in "Start" type the folder target to be opened when Powershell Shortcut is triggered

查看更多
登录 后发表回答