3

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.

8
  • Why do you think you need to run cd and dir in CMD in the first place? PowerShell can do those things by itself. Please take a step back and describe the actual problem you're trying to solve instead of what you perceive as the solution. Commented Nov 22, 2017 at 9:54
  • That is just an example. I need to be able to run more than one command. Commented Nov 22, 2017 at 17:04
  • I am trying to automate a deployment and need to execute several steps at the command prompt from my powershell script. The problem is I cannot get the second step to execute. The cd and dir are just two simple commands in my quest to get this to work. Commented Nov 22, 2017 at 17:07
  • Again, why is the Command Prompt a requirement? PowerShell can run external commands all by itself. Commented Nov 22, 2017 at 17:18
  • I am deploying a COTS product and the vendor directions require using the command prompt for the deployment. It is a JAVA app and uses Ant. Commented Nov 22, 2017 at 18:00

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.