The function below is meant to implement blocked sleep in PowerShell
It gets the following error executing Start-Sleep
cmdlet:
"Cannot validate argument on parameter 'Seconds'. The argument is null, empty, or an element of the argument collection contains a null value"
The echo prints the correct argument value, but the argument is not passed to the cmdlet. I tried a local variable with the same result. Tried to cast it to string or integer - no avail. The only way it works if the number is hard coded
function BlockedSleep($numSecs)
{
echo "Sleeping $($numSecs) seconds"
$job = Start-Job {Start-Sleep -s $numSecs }
Wait-Job $job >$null #this supresses job output to console
Receive-Job $job
}