Created
July 20, 2020 15:59
-
-
Save billkindle/43572440f87135ed777d4a50cb331e5f to your computer and use it in GitHub Desktop.
Just a little PowerShell Do-Until loop I used for searching an active log file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do { | |
# set variables for searching Service.log | |
$now = Get-Date -Format 'yyyy-MM-dd' | |
$log = 'C:\Users\wkindle\Desktop\Service_Test.log' | |
$logstr = 'updating status to READY' | |
Write-Output "Searching for READY status" | |
# using this to create a timeout counter | |
$integer++ | |
#Wait 5 seconds | |
Start-Sleep -seconds 5 | |
# Take the last 15 log entries from today and store as a variable | |
# I choose 15 becuase I don't know how fast the log is written or how quickly READY status is returend | |
$StatusMessage1 = (Select-String -Path $log -Pattern $now | Select-Object -Last 15) | |
$StatusMessage2 = (Select-String -InputObject $StatusMessage1 -Pattern $logstr | Select-Object -Last 1) | |
} until ($StatusMessage2 -ne $null -or $integer -eq 120) # Timeout the script after running 10 minutes | 5*120 = 600/60 = 10mins | |
Write-Output "READY STATUS FOUND" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment