Open Powershell in a specific directory from shortcut

后端 未结 9 1286
再見小時候
再見小時候 2021-01-30 12:22

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

相关标签:
9条回答
  • 2021-01-30 12:48

    Ok - you need to use the & parameter to specify it's a powershell comand & the syntax is slightly different:

    %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe 
    -noexit -command "& {cd c:\path\to\open}"
    
    0 讨论(0)
  • 2021-01-30 12:50

    If you want powershell to start as admin and run in a specific directory, even on a different drive, it is better to use the Set-Location command. Follow these steps

    1. Create a ShortCutLink with the target being the powershellcommand exe.
    2. Leave Start in: blank. (Normally this starts in current working directory when blank; but we do not care.)
    3. Change Target to this with your targets for powershell and locations:

      C:\Windows\...\v1.0\powershell.exe -noexit -command "Set-Location D:\_DCode\Main"

    4. Click Advanced... and select Run as administrator.
    5. Click OKs out.

    Don't forget the handy trick to change the colors of the shortcut from the Colors tab. That way if you have two or more links which open powershell windows, seeing a different color can visually let you know which shell one is working in.

    0 讨论(0)
  • 2021-01-30 12:55

    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

    0 讨论(0)
  • 2021-01-30 12:59

    I just wanted to add my Developer Powershell link ... for the records.

    C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noe -c "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell d998f19b; cd c:\dev\}"
    

    This will start the Developer Powershell (VS 2019) in c:\dev\.

    0 讨论(0)
  • 2021-01-30 13:02

    Use this command.

    powershell.exe -noexit -command "cd c:\temp"
    

    -NoExit: Do not exit after running startup commands.

    0 讨论(0)
  • 2021-01-30 13:09

    You can also set the "Start in" shortcut field to your desired location.

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