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
Windows OSPowershell
26 Comments4 Solutions167 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


Should I be using a for each loop?

p.s new with posh so please excuse any misused terms
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 4 Answers and 26 Comments.
Join the Community
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 4 Answers 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