PSnewbie
PSnewbie

Reputation: 37

Having problems getting a Powershell Timeout working

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..."}}

Upvotes: 0

Views: 139

Answers (1)

Mike Shepard
Mike Shepard

Reputation: 18156

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.

Upvotes: 2

Related Questions