Here's an example of using FileSystemWatcher. You can modify the code to stay in the do/while for only a certain period by 'remembering' the time you entered the loop and subtracting that from the current time after each 'sleep'. If the resulting time difference is less than the period you define, stay in the loop, otherwise use a 'break' to exit the loop.
PowerShell Monitor and Run
How to monitor a folder for a new sub-folder created and then monitor the new subfolder for a file for a specific timeframe? When the file is detected within the timeframe, run another file in a different drive and exit. If the file is not detected within the timeframe, then exit?
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = 'Z:\abc'
$watcher.Filter ='.'
IncludeSubdirectories = $true
$watcher.Filter = 'xyz.txt'
$watcher.EnableRaisingEvents = $true
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -action {
$path =$event.SourceEventArgs.FullPath
$changeType + $Event.SourceEventsArgs. ChangeType
...STUCK HERE