I am learning Powershell and along with that trying to work on different projects, I wanted to create type of loop with powershell command which check for existence of particular keyword “Hello” in “c:\temp\loop.txt” 9 times with the interval of 10 mints.
If it found that keyword “hello” after any interval of 10 mints then it must exit from the loop.
What help exactly do you need? What have you tried so far?
Please keep in mind - This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.
We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.
I was using below command so that it should get exit from the loop if it found hello keyword in C:\temp\loop.txt else keep checking for the keyword hello after every 5 seconds.
You have to move the Get-Content command inside the loop. Otherwise you will check the initial state again and again and again.
… but actually … the comparison operator -contains checks for a single element in an array of elements. If your input text file has more words on the same line together with “hello” your condition will not work.
I’d recommend using
instead
So you have to add a counter and increase this counter with each loop iteration and check both conditions combined with an -or or an -and.
You may elaborate a little more detailed what you’re actually trying to achieve … there might be a better way than the one you think you should go.