PowerTip: Generate Random Beeps with PowerShell

PowerTip: Generate Random Beeps with PowerShell

  • Comments 3
  • Likes

Summary: Use Windows PowerShell to generate random beeps.

Hey, Scripting Guy! Question How can I generate random beeps by using Windows PowerShell?

Hey, Scripting Guy! Answer Create a range of numbers between 190 and 8500 that will determine the tone.
          Use the Get-Random cmdlet to choose a random number of tones. Pipe the results to the 
          ForEach-Object cmdlet, and call the Beep static method from the system.console class.
          The first number determines the tone, and the second number determines the length of the tone.
          Here is an example of this technique:

190..8500 | Get-Random -Count 35 | ForEach {[console]::Beep($_, 150)}

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • thank you

  • Great script. I was able to modify it a bit to randomize the duration part as well.

    190..8500 | Get-Random -Count 35 | ForEach {[console]::Beep($_, $(50..500 | Get-Random))}

  • HAHA, one of my favorite power tips yet. Gonna use it to scare my supervisor when he's working on the servers.