Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7777523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:09:51+00:00 2026-06-01T18:09:51+00:00

I have 4 servers on which I need to do some processing. The processing

  • 0

I have 4 servers on which I need to do some processing. The processing is in two parts:

  1. Run a batch file
  2. Run a powershell script

I need the batch files to run simultaneously on all the servers, ideally at precisely the same time. I have currently set up scheduled tasks on all of the servers because we use a network time service so they are in synchronisation.

I then need to run the Powershell scripts one after the other, i.e. when the script on Server1 finishes, the script on Server2 begins, then when it finishes, Server3 begins, etc. This could be done in the same way as Part 1, i.e. scheduled tasks, however the tasks take massively varying lengths of time to complete.

I want to avoid the scheduled tasks option for the batch files, even though the time is in sync, I would rather have them all kick off from one place. Finally I need suggestions on how to go about invoking the Powershell scripts in a queue-like manner across different servers. Is this possible?

Edit 2012-04-11

With the help of Keith Hill’s answer I have managed to get closer to what I need. It would make sense for me to post my code at this point:

# $strServers[0] must correspond to $strFiles[0]
# $strServers[1] must correspond to $strFiles[1]
# etc.
$strServers = @(
    "di-ads-02",
    "di-ads-03", 
    "si-ads-02",
    "vm-ads-02"
);    
$strFiles = @(
    "D:\Utilities\test.ps1",
    "D:\Utilities\test.ps1", 
    "C:\Utilities\test.ps1",
    "D:\Utilities\test.ps1"
);

try 
{
    for ($i = 0; $i -lt $strFiles.Count; $i++)
    {
        $job = Invoke-Command -cn $strServers[$i] -ScriptBlock {Invoke-Expression $strFiles[$i]} -AsJob;
        # Wait for $job to finish for a maximum of 60 minutes
        Wait-Job $job -Timeout 3600;
    }
}
catch 
{
    Write-Host "ERROR : " + $_;
}

I get the following output from PowerShell:

Id              Name            State      HasMoreData     Location             Command                  
--              ----            -----      -----------     --------             -------                  
47              Job47           Failed     False           di-ads-02            Invoke-Expression $str...
49              Job49           Failed     False           di-ads-03            Invoke-Expression $str...
51              Job51           Failed     False           si-ads-02            Invoke-Expression $str...
53              Job53           Failed     False           vm-ads-02            Invoke-Expression $str...

It looks to be getting halfway there, but the execution is failing. First I thought maybe it was running but just wasn’t reporting back correctly. I then modified the test.ps1 script so that it outputs two files (stderr and stdout) when it runs, so as to leave some proof behind. When I remote onto those servers and run the scripts locally, those files are generated, but doing it as the above script doesn’t work.

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:09:52+00:00Added an answer on June 1, 2026 at 6:09 pm

    If you can enable PowerShell remoting on the servers, you can orchestrate the execution of the PowerShell script using jobs from one machine e.g.:

    $servers = 'server1','server2','server3','server4'
    foreach ($server in $servers)
    {
        $job = Invoke-Command -cn $server -Filepath c:\myscript.ps1 -AsJob
        Wait-Job $job -Timeout 180 # wait maximum of 3 minutes
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some service which does some file processing. It may need to map
I have a bunch of servers, on which I run experiments using screen .
I have some WSDL from which I need to generate a web service implementation.
I have a php script that does some processing (creates remittance advice PDFs, self-billing
I have a client server application in which I need to transmit a user
I have data in an SQL Server 2005 database which I need to copy
I have a client server application in which the server and the client need
I have a chrome extension which have a server-side javascript and I need this
I have set up 2 servers which are linked. From my LOCAL SERVER, I
I have a bunch of SQL servers which I periodically performs maintainance on (Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.