Open Powershell in a specific directory from a shortcut

It sounds like it should be so simple ... I have to be dumb.

All I want to do is make a Windows shortcut that opens Powershell to a specific directory:

I use the goal:

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

Put it just spits out the command as text.

+63
windows-7 powershell shortcuts
Jan 09 '13 at 10:53 on
source share
7 answers

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

+99
Jan 09 '13 at 11:00
source share

You can also set the โ€œEnter toโ€ shortcut field to the desired location.

+32
Jan 09 '13 at 12:21
source share

to try:

 %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "cd c:/path/to/open" 
+4
Jan 9 '13 at 11:01
source share

Good - you need to use the & parameter to specify its powershell command, and the syntax is slightly different:

 %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "& {cd c:\path\to\open}" 
+3
Jan 09 '13 at
source share

Copy this code into notepad and save it using the reg extension. Double-click the resulting file. If you receive a message about importing into the registry, click "Yes" and then "OK." Go to any folder in Explorer and call the context menu. This is usually done by right-clicking.




 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\Background\shell\PShell] "MUIVerb"="Open in Powershell Window" [HKEY_CLASSES_ROOT\Directory\Background\shell\PShell\command] @="c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'" 
+1
Nov 07 '16 at 5:43
source share

If you need an explorer, right-click and 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




Please note that you can download a detailed PowerShell startup script from Windows Explorer .

+1
Nov 10 '16 at 6:12
source share

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

  • Create ShortCutLink, the target will be the powershellcommand exe command.
  • Leave Start in: blank. (This usually starts in the current working directory when it's empty, but we don't care.)
  • Change Target to this using your goals for powershell and locations:

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

  • Click Advanced... and select Run as administrator .
  • Click OK out.



Do not forget to use a convenient trick to change the colors of the shortcut on the Colors tab. Thus, if you have two or more links that open PowerShell windows, a different color view can visually tell you which shell is working.

+1
Aug 28 '17 at 13:54 on
source share



All Articles