I have to open 2 URLs from powershell. Each creates a log file. Once the log file of the 1st URL is complete, the 2nd URL has to be launched. The completion of the file is indicated by a string "end of log". Each log takes a minimum of 15 minutes. Since the duration is not certain, I didn't use sleep commanlet.
1 Answer
Ok so its rather simple, You use Select-String to search a text file for a string. You do this in a while block so while Select-String returns false (-Quiet makes the cmdlet return a bool true or false if the value exists in the file) Wait the amount of time and then check again.
While ($(Select-String -Path 'C:\Logs\File1.txt' -Pattern 'end of log' -quiet) -eq $False) { Write-Host "No end of log in file 1 waiting.." Sleep -Seconds 3 } Since your first script takes 15minutes to finish, You might want to make it wait longer between checks since if its to frequent it might slow down the first script.
4 Comments
S.Shaw
Thanks! is it possible not to return anything on the console until the string is identified? show nothing on the console and open the 2nd url once the 1st log is complete.
Nick
Just remove line that says write-host and it will not display anything. Let me know if thats what your after.
S.Shaw
hey Nick! thank you so much, this worked just right!
Nick
@S.Shaw Thats great to hear glad it worked, Can you mark the question as answered so anyone else visiting the article knows this helped