How start PowerShell from cmd by specific path

13

3

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.

Marslo

Posted 2013-04-25T13:26:16.650

Reputation: 884

Or %SystemRoot% – Amit Naidu – 2018-03-08T02:52:09.960

If you must use the full path to powershell.exe, better to use %windir%. – Jay Bazuzi – 2013-04-28T05:52:48.447

Answers

13

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'"

Der Hochstapler

Posted 2013-04-25T13:26:16.650

Reputation: 77 228

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 – 2013-04-26T05:59:23.983

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 – 2013-04-26T06:24:32.760

@Marslo: You can also use ' to wrap the path. Like: -Command "Set-Location 'C:\\Program Files'" – Der Hochstapler – 2013-04-26T08:35:54.097

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 – 2013-04-26T12:57:52.207

@OliverSalzburg: Just found your answer while searching. Can you perhaps solve my closely related problem as well?

– Karan – 2013-06-17T02:55:53.823

0

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

Daniel F

Posted 2013-04-25T13:26:16.650

Reputation: 751