PowerTip: Launch Cmd.exe Commands from PowerShell

PowerTip: Launch Cmd.exe Commands from PowerShell

  • Comments 1
  • Likes

Summary: Launch legacy applications from Windows PowerShell.

Hey, Scripting Guy! Question Can I execute an old batch script in Windows PowerShell?

Hey, Scripting Guy! Answer To launch an old command or batch file from within a Windows PowerShell script, launch Cmd.exe with the /C parameter:

CMD.EXE /C PAUSE

Or if it’s a .bat or .cmd file, you can put it directly within the Windows PowerShell script and run it:

\BAT\CAVE\RUNME.CMD

Note Your results will be in the $LASTEXITCODE.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Thanks for the post.

    If I do PS remoting to many machines and execute Invoke-Command -session $Sessid {cmd /c Shutdown -r -t 0}, how do I specify $LASTEXITCODE here?