Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run multiple commands from cmd.exe in PowerShell

Tags:

powershell

cmd

I have the following line that I want to execute from PowerShell:

Start-Process cmd.exe -Credential "doh\account" "`"cd c:\Projects `& dir`""

The problem is that the second command does not execute. I have looked at many articles and have tried multiple combinations of quotes and back ticks without success.

like image 601
Rosalind Avatar asked May 16 '26 05:05

Rosalind


1 Answers

This should do what you want:

Start-Process cmd.exe -credential "doh\account" -ArgumentList "/K cd c:\projects & dir"

I ran "cmd /?" and it has the following argument available: "/K Carries out the command specified by string but remains"

Still not sure why you want to do this though, if you want to elaborate on it we might able help more.

like image 51
Dizzy Avatar answered May 18 '26 03:05

Dizzy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!