July 13th, 2014

PowerTip: Generate Random Beeps with PowerShell

Doctor Scripto
Scripter

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

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.