PowerTip: Generate Random Beeps with PowerShell

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)}

Comments (3)

  1. Anonymous says:

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

  2. Chirag64 says:

    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))}