none
Submitting PowerShell scripts to be executed in parallel with arguments

    Question

  • I have two linked questions related to a PowerShell script that must be executed in background and in parallel.

    Let me explain: I need to call a script like C:\myscripts\script1.ps1 and to pass the data related to several people.

    For each person I need to pass $name, $surname and $age.

    So my script should sound like:

    $name = "Jane"

    $surname = "Doe"

    $age = 40

    start C:\myscripts\script1.ps1 $name, $surname, $age

    $name = "Jane"

    $surname = "Smith"

    $age = 25

    start C:\myscripts\script1.ps1 $name, $surname, $age

    How can I translate it in (working) PowerShell code?

    Regards

    Marius

    Thursday, April 20, 2017 9:11 PM

All replies

  • You need to start by learning the basics of PowerShell.

    You can also use help to get information on using PowerShell.

    help about_parameters


    \_(ツ)_/

    Thursday, April 20, 2017 9:21 PM
    Moderator
  • Hi Marius,

    Try this:

    powershell.exe  -file 'C:\myscripts\script1.ps1' -command '&{$name,$age}'

    The –command parameter accepts a single Windows PowerShell command, along with any parameters that command requires. Enclose the entire command string in quotes if it contains any spaces or parameters. You can also include a complete pipeline of multiple cmdlets, if needed.

    You could also use the –file parameter. This accepts the path and filename of a .PS1 file. Windows PowerShell will then execute that file’s contents. This is a much easier way to run a complex series of commands than trying to jam them all into the –command parameter. Keep in mind that the shell’s Execution Policy affects script execution, which brings us to the next point.

    https://technet.microsoft.com/en-us/library/hh987044.aspx

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, April 21, 2017 5:43 AM
    Moderator