troubleshooting Question

Powershell - script to tail log file on multiple servers

Avatar of Robert Perez-Corona
Robert Perez-CoronaFlag for United States of America asked on
PowershellWindows OS
26 Comments1 Solution167 ViewsLast Modified:
I need to polish up this script. I need it to run across multiple(5 - all have the log file in the same location) windows systems instead of just one. I am having a hard time figuring out how to ensure I can "tail" the log for the entry on all 5 servers simultaneously and return the 'OK' or terminate the job only when the log entry is generated on all 5 servers and not just let's say 4 of them.

 At the moment it's meant to do the following:

1. Start a service,
2. "Tail" a log file
3. Confirm that the log file contains the entry ($waitfor)
4. Once the log entry is generated, terminate

$serviceB = "my application service"
$logfile2 = "F:\App\log\wrapper.log"
$waitFor = "[4.2.3.GA (build: SVNTag=JBoss_4_2]”

Write-Host "Starting $serviceB"
Start-Service $serviceB
Write-Host "Waiting for $waitFor in $logfile2"
while(!((Get-Content $logfile2 -Tail 30) | ? {$_ -match $waitFor}))
    Start-Sleep -Seconds 5

Open in new window


Should I be using a for each loop?

p.s new with posh so please excuse any misused terms
"Batchelor", Developer and EE Topic Advisor

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2015

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 26 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 26 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros