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.

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

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'"
  • 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 Apr 26 '13 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 Apr 26 '13 at 6:24
  • @Marslo: You can also use ' to wrap the path. Like: -Command "Set-Location 'C:\\Program Files'" – Der Hochstapler Apr 26 '13 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 Apr 26 '13 at 12:57
  • @OliverSalzburg: Just found your answer while searching. Can you perhaps solve my closely related problem as well? – Karan Jun 17 '13 at 2:55

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.