Why does this PowerShell script hang?

Posted by jshin47 on Server Fault See other posts from Server Fault or by jshin47
Published on 2012-06-06T20:50:34Z Indexed on 2012/06/06 22:42 UTC
Read the original article Hit count: 172

Filed under:

Today I had to use Start-Sleep many times so I thought I would create a shortcut function for it, sleep($time). However, whenever I entered the function it never exits! It must be an issue with either the data type for the argument for Start-Sleep or the way I am declaring the function. Instead of posting the whole script, I've posted this useless one that would make a familiar beep pattern if it worked:

function beep {
    Write-Host `a
}

function sleep {

    param([int]$time)

    Start-Sleep -m $time
}

beep
sleep(300)
beep
sleep(200)
beep
sleep(50)
beep
sleep(300)
beep
sleep(450)
beep
sleep(200)
beep

© Server Fault or respective owner

Related posts about powershell