20

I want to start PowerShell (C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe) from windows 7 default command line (cmd) and go to the specific path.

I used the command:

start C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe

It'll work, and show the powershell window.

But, if I use:

start C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe Set-Location c:\

The black window will flash quickly.

How can I open powershell from cmd by the specific path? Thanks in advance.

2
  • If you must use the full path to powershell.exe, better to use %windir%.
    – Jay Bazuzi
    Commented Apr 28, 2013 at 5:52
  • Or %SystemRoot%
    – Amit Naidu
    Commented Mar 8, 2018 at 2:52

2 Answers 2

20

Try this:

powershell -NoExit -Command "Set-Location c:\\"

If your path contains spaces, you can wrap it in single-quotes, like so:

powershell -NoExit -Command "Set-Location 'c:\\program files'"
5
  • How can I do when the path has space? for example, path1 = c:\Program files\vim, then > 'powershell -NoExit -Command "Set-Location ' + path1 + '"' only can open the powershell but cannot cd in the path1
    – Marslo
    Commented Apr 26, 2013 at 5:59
  • Hi, I fix that. I using two strings, s1 = 'start C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command '; s2 = '"Select-Location ' + "'" + path1 + "'" + '"', and command = s1 + s2. then it works
    – Marslo
    Commented Apr 26, 2013 at 6:24
  • 1
    @Marslo: You can also use ' to wrap the path. Like: -Command "Set-Location 'C:\\Program Files'" Commented Apr 26, 2013 at 8:35
  • Yep! Thanks @Oliver Salzburg . :) I written this for gvim. I want to press F3(or other shortcuts) will show command line (Powershell) and cd in the current file path.
    – Marslo
    Commented Apr 26, 2013 at 12:57
  • @OliverSalzburg: Just found your answer while searching. Can you perhaps solve my closely related problem as well?
    – Karan
    Commented Jun 17, 2013 at 2:55
3

What Windows 10 uses in the Registry in order to open a PowerShell instance by shift-rightclicking in an Explorer window or on the Desktop ("Open PowerShell window here") is the following:

powershell.exe -noexit -command Set-Location -literalPath '%V'

This can be found at Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .