Example 1.
$returned = $false | Wait-Object -ScriptBlock {Test-Path C:\Wait\For\Removal } -TimeOut 10
if($returned -ne $null) {
#do something
}
else {
#do something else
}
Also this lets me use a try / catch with the ErrorAction set to stop causing the the catch to trigger in event of failure.
Example 2.
try {
$returned = $false | Wait-Object -ScriptBlock {Test-Path C:\Wait\For\Removal } -TimeOut 10 -ErrorAction Stop
}
catch {
exit
}