Rinning commands from a PS script

This topic contains 2 replies, has 2 voices, and was last updated by  marius 2 months ago.

  • Author
    Posts
  • #72652

    marius
    Participant

    I need to execute 3 commands from a PowerShell script.
    The commands look like:

    change user /install
    c:\mydir\mysetup.exe
    change user /execute
    

    I created a .cmd file (let's say, mycmd.cmd) and I try to launch it from my .ps1 script but I am unable to find the right syntax. Based on what I see the following syntax should work:

    & cmd.exe /c c:\mydir\mycmd.cmd
    

    but it doesn't...
    Can anybody please help?
    Can I send each single line from my .ps1 file and run it in a synchronous way?
    Regards
    marius

  • #72656

    Don Jones
    Keymaster

    Have you tried just renaming your script from .cmd to .ps1, and letting PowerShell run the whole thing?

    • #72688

      marius
      Participant

      Many thanks for your answer.
      I made a test but it looks like commands in a .ps1 file are executed asynchronously.
      So, for example, the third command is executed without waiting for the second to complete.
      If I create a .cmd file the commands are executed in synchronous way, that's the reason because I considered creating and running a .cmd file.
      How can I solve my issue?
      Regards
      Marius

You must be logged in to reply to this topic.