I wrote a PWSH script to monitor my server log.
The result works fine when running the script directly on SolarWinds OS (Windows 2022, PWSH 7.5). However, the script's result differs when it runs on the SolarWinds PowerShell module.
to help to simulate my situation i post my script and logfile.

My code:
#logfile
$output = Get-Content -Path $logifle.txt
# Read all lines from the log file
$logLines = $output
# Initialize variables
$startIndex = $null
$extractedSection = @()
# Find the first occurrence and extract only the first section
for ($i = 0; $i -lt $output.Count; $i++) {
if ($logLines[$i] -match "Works on pacemaker-remote.") {
$startIndex = $i
break
}
}
# If we found the starting point, extract the section until the next "Works on pacemaker-remote." or end of file
if ($startIndex -ne $null) {
for ($j = $startIndex + 1; $j -lt $output.Count; $j++) {
if ($output[$j] -match "Works on pacemaker-remote.") {
break # Stop extracting at the next occurrence
}
$extractedSection += $output[$j]
}
}
# Display extracted section
<# if ($extractedSection.Count -gt 0) {
Write-Output "==== Extracted Section ===="
$extractedSection | ForEach-Object { Write-Output $_ }
} else {
Write-Output "No section found."
} #>
# Process the extracted log section
$offlineComputers = $extractedSection -split "`n" | ForEach-Object {
if ($_ -match "'(.*?)' is 'offline'") {
$matches[1]
}
}
$onlineComputers = $extractedSection -split "`n" | ForEach-Object {
if ($_ -match "'(.*?)' is 'online'") {
$matches[1]
}
}
$offlinenum = $offlineComputers.Count
$onlinenum = $onlineComputers.Count
if ($offlineComputers.Count -eq 0) {
Write-Output "Message.Status: Healthy"
Write-Output "Statistic.Status: 0"
write-output "Statistic.online_member: $onlinenum"
exit 0
} else {
Write-Output "Message.Status: warning"
Write-Output "Statistic.Status: 2"
Write-Output "Message.offline_member: $offlinecomputers"
Write-Output "Statistic.offline_member: $offlinenum"
write-output "Statistic.online_member: $onlinenum"
exit 2
}
Log file:
2025-04-17 10:50:11.590 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute30' is 'online' (current: 'online').
2025-04-17 10:50:11.590 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute31.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:50:11.590 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute32.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:50:11.590 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute33.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:11.649 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] Works on pacemaker-remote.
2025-04-17 10:51:12.450 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute02' is 'online' (current: 'online').
2025-04-17 10:51:12.451 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute03' is 'online' (current: 'online').
2025-04-17 10:51:12.451 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute04' is 'online' (current: 'online').
2025-04-17 10:51:12.451 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute05.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.451 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute06.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.451 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute07.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.451 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute08.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.452 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute09.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.452 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute10.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.452 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute11.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.452 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute12.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.452 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute13.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.452 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute14.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.452 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute15' is 'online' (current: 'online').
2025-04-17 10:51:12.453 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute16.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.453 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute17' is 'online' (current: 'online').
2025-04-17 10:51:12.453 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute18' is 'online' (current: 'online').
2025-04-17 10:51:12.453 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute19' is 'online' (current: 'online').
2025-04-17 10:51:12.453 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute20.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.453 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute21.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.453 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute22.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.454 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute23.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.454 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute24.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.454 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute25.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.454 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute26.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.454 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute27.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.454 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute28.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.454 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute29' is 'online' (current: 'online').
2025-04-17 10:51:12.455 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute30' is 'online' (current: 'online').
2025-04-17 10:51:12.455 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute31.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.455 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute32.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:51:12.455 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute33.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:12.514 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] Works on pacemaker-remote.
2025-04-17 10:52:13.310 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute02' is 'online' (current: 'online').
2025-04-17 10:52:13.311 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute03' is 'online' (current: 'online').
2025-04-17 10:52:13.311 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute04' is 'online' (current: 'online').
2025-04-17 10:52:13.311 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute05.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.311 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute06.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.312 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute07.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.312 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute08.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.312 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute09.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.312 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute10.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.312 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute11.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.312 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute12.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.313 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute13.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.313 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute14.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.313 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute15' is 'online' (current: 'online').
2025-04-17 10:52:13.313 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute16.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.313 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute17' is 'online' (current: 'online').
2025-04-17 10:52:13.313 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute18' is 'online' (current: 'online').
2025-04-17 10:52:13.314 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute19' is 'online' (current: 'online').
2025-04-17 10:52:13.314 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute20.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.314 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute21.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.314 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute22.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.314 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute23.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.314 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute24.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.314 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute25.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.315 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute26.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.315 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute27.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.315 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute28.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.315 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute29' is 'online' (current: 'online').
2025-04-17 10:52:13.315 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute30' is 'online' (current: 'online').
2025-04-17 10:52:13.315 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute31.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.316 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute32.LAB.GD' is 'online' (current: 'online').
2025-04-17 10:52:13.316 7 INFO masakarimonitors.hostmonitor.host_handler.handle_host [-] 'opstk-compute33.LAB.GD' is 'online' (current: 'online').