1

I am trying to run a command in CMD, but would like to run in through PowerShell.

Invoke-Item opens CMD, but I don't how to pass in program.exe argument > file.txt

2 Answers 2

2

To run cmd.exe from PowerShell, you don't need to use invoke-item e.g.:

cmd /c c:\windows\system32\ipconfig > file.txt

However, why not just run?

ipconfig > file.txt
Sign up to request clarification or add additional context in comments.

Comments

0

try passing the command in directly with the full path qualifier of program.exe like:

$test= "c:\windows\system32\program.exe argument > file.txt"  
Invoke-Expression $test 

2 Comments

- The argument contains an .exe file and some text...It's after the cmd.exe. So, it looks like this: Invoke-Item c:\windows\system32\cmd.exe program.exe argument > file.txt
try the alternative instead that I just edited. The cmd.exe is not needed.

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.