Start a separate PowerShell process (Start-Process
using the -Passthru switch) and save the value in a variable. Then use Start-Sleep -Seconds (5*60)
. When the launching script awakes, check the status of the process that you started. If it's still running, stop it.
If the 2nd script finishes before 5 minutes you'll still wait 5 minutes, though.
Alternatively, you can create a loop in the launching script that repeatedly waits a few seconds, checks to see if the 2nd script is still running and either exits the loop if the 2nd script is finished or stops the process if the elapsed time is greater than 5 minutes.