Rinning commands from a PS script

Welcome Forums General PowerShell Q&A Rinning commands from a PS script

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 11 months ago.

  • Author
  • #72652

    Topics: 21
    Replies: 15
    Points: 1
    Rank: Member

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

    change user /install
    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?

  • #72656

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

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

    • #72688

      Topics: 21
      Replies: 15
      Points: 1
      Rank: Member

      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?

The topic ‘Rinning commands from a PS script’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort