4

So I'm using the command

Start-Process powershell -Verb runas -ArgumentList $cmds

where $cmds is

$cmds = "cd C:\", "dir"

I just want the new powershell that I'm opening to run multiple commands before it automatically closes.

3
  • I'm not sure of your use case, but I would probably create a script file containing the commands and run that. Commented May 22, 2013 at 17:32
  • @Bill_Stewart How would the script file help? I'm not saying it won't, I'm saying I don't understand. If what I have above won't work, what do I have to do to get it to work? Commented May 22, 2013 at 17:36
  • This depends on your use case. A scriptblock (like the answer below) may do exactly what you want. Commented May 23, 2013 at 12:37

1 Answer 1

8

Change $cmds to:

$cmds = {"cd C:\"; "dir";}

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

1 Comment

You are correct sir. The one problem (which was my mistake) was that you need to escape the \ with another \

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.