No announcement yet.

Pass string from one Powershell script to another

  • Filter
  • Time
  • Show
Clear All
new posts

  • Pass string from one Powershell script to another

    I currently run a Powershell script that will pull the list and then initiate a command remotely on each workstation. However, it runs them consecutively instead of concurrent, i.e.. server2 starts after server1 completes.

    What I want to do is use a Powershell script to read a list of workstation names and then it initiates another Powershell script, for each workstation in the list. I want to start a new Powershell session to run for each workstation as the loop is processed, which it can do by initiating a second .ps1 script in the loop.

    For example, list.txt reads:

    Here is my script -

    $computers = gc "C:\list.txt"
    foreach ($computer in $computers) {
    start-process powershell -argumentlist ".\launcher.ps1 $computer"}

    I need to pass the string/variable of $computer on to the second script(launcher.ps1). It needs this value in order to run correctly.

    Everything works between both .ps1's except passing this value, which is the most critical component.

    Any ideas?

  • #2
    How are you referencing it in your script? It's a little meta because you're passing the arguments to powershell which executes the script with the next argument. So in the script it's reference should be $arg[0].

    Network Consultant/Engineer
    Baltimore - Washington area and beyond