Powershell – Why does this PowerShell script hang

powershell

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

Best Answer

My system already has an alias for Start-Sleep called, oddly enough, sleep. run this to see if you have it dir alias:sleep. Try a different name for your function to see if that helps.