0

Can someone please tell me what I'm doing wrong here, it's killing me... I want the loop to stop if it's been over a minute or SomeFile.txt shows up. Thanks

$EndTimer = (Get-Date).AddMinutes(1)
while (((Get-Date) -le $EndTimer) -or (!(Test-Path "$LocPath\SomeFile.txt"))) {2..1 | ForEach {Start-Sleep -Seconds $_ ;"Processing..."}}
2
  • What isn't working for you? Does it stop too soon? Never? Not if the file is there? Do you get errors? Commented Feb 6, 2018 at 21:06
  • The loop only stops when the "$LocPath\SomeFile.txt" shows up. I want it to stop when a minute is up OR the file shows up. Commented Feb 6, 2018 at 21:18

1 Answer 1

2

You should be using -and instead of -or in your condition.

You want the loop to continue "while" the timer isn't expired and the file doesn't exist.

Sign up to request clarification or add additional context in comments.

2 Comments

I want the loop to continue "while" the timer isn't expired OR the file doesn't exist.
As soon as one of the conditions is false (it's past the time) or the file starts existing, you want it to exit. You don't need both to be false (which would use an -or).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.