12 Mar 2012 @ 7:24 AM 

Last week I was playing around with re-writing a few of my old scripts to PowerShell.
I don’t do this because I have to, but to learn things because, trust me, you will encounter some things that will make you investigate and learn some more amazing things of PowerShell Glimlach

The second script involved letting the computer ‘beep’ when an error occurred in a logon script. It may sounds crazy, but my customer wanted it back in the day so I wrote it.

So, to create a beep with PowerShell, simply use:

$([char]7)

And to get 100 sequential beeps:

1..100 | % { $([char]7) }

So, fun right? But’s that is just one beep, one tone… there has to be more than that, right?
Well, yes there is… but not with the ‘char’ method as I used. Of all the characters (char) there is only one that provides for a beep and again, it’s just one tone and one length.

When you should use WMI and call for classes, you can do a lot more Glimlach
For example, when you use [console]::beep(440,1000) you will get a tone with a pitch of 440 and a length of 1000 milliseconds (1 second).

And now… let’s go crazy!

The Imperial March (Star Wars)

[console]::beep(440,500)
[console]::beep(440,500)
[console]::beep(440,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,1000)
[console]::beep(659,500)
[console]::beep(659,500)
[console]::beep(659,500)
[console]::beep(698,350)
[console]::beep(523,150)
[console]::beep(415,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,1000)

And for all you ‘cult’people out there, here is Close Encounters of the 3th Kind:

[console]::beep(900,400)
[console]::beep(1000,400)
[console]::beep(800,400)
[console]::beep(400,400)
[console]::beep(600,1600)

Now that we have some basics, maybe you want a little time in between the tones? Let’s call that project “Mission Impossible”:

[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(932,150)
Start-Sleep -m 150
[console]::beep(1047,150)
Start-Sleep -m 150
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(699,150)
Start-Sleep -m 150
[console]::beep(740,150)
Start-Sleep -m 150
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(932,150)
Start-Sleep -m 150
[console]::beep(1047,150)
Start-Sleep -m 150
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(699,150)
Start-Sleep -m 150
[console]::beep(740,150)
Start-Sleep -m 150
[console]::beep(932,150)
[console]::beep(784,150)
[console]::beep(587,1200)
Start-Sleep -m 75
[console]::beep(932,150)
[console]::beep(784,150)
[console]::beep(554,1200)
Start-Sleep -m 75
[console]::beep(932,150)
[console]::beep(784,150)
[console]::beep(523,1200)
Start-Sleep -m 150
[console]::beep(466,150)
[console]::beep(523,150)

Post to Twitter

Posted By: Jeff Wouters
Last Edit: 12 Mar 2012 @ 07:24 AM

EmailPermalink
Tags
Categories: Geeky, PowerShell


  • Michael

    Thats great :-)

  • http://twitter.com/jsclmedave Tim Bolton

    Brilliant..!

  • lesaboteur

    Here is the whole imperial march:
    beep(440,500)
    beep(440,500)
    beep(440,500)
    beep(349,350)
    beep(523,150)

    beep(440,500)
    beep(349,350)
    beep(523,150)
    beep(440,1000)

    beep(659,500)
    beep(659,500)
    beep(659,500)
    beep(698,350)
    beep(523,150)

    beep(415,500)
    beep(349,350)
    beep(523,150)
    beep(440,1000)

    beep(880,500)
    beep(440,350)
    beep(440,150)
    beep(880,500)
    beep(830,250)
    beep(784,250)

    beep(740,125)
    beep(698,125)
    beep(740,250)

    beep(455,250)
    beep(622,500)
    beep(587,250)
    beep(554,250)

    beep(523,125)
    beep(466,125)
    beep(523,250)

    beep(349,125)
    beep(415,500)
    beep(349,375)
    beep(440,125)

    beep(523,500)
    beep(440,375)
    beep(523,125)
    beep(659,1000)

    beep(880,500)
    beep(440,350)
    beep(440,150)
    beep(880,500)
    beep(830,250)
    beep(784,250)

    beep(740,125)
    beep(698,125)
    beep(740,250)

    beep(455,250)
    beep(622,500)
    beep(587,250)
    beep(554,250)

    beep(523,125)
    beep(466,125)
    beep(523,250)

    beep(349,250)
    beep(415,500)
    beep(349,375)
    beep(523,125)

    beep(440,500)
    beep(349,375)
    beep(261,125)
    beep(440,1000)

  • http://www.jeffwouters.nl Jeff Wouters

    Whahaha! Nice :-D Thanks for sharing!

  • kiquenet kiquenet

    Hi, it’s great, and funny. I would like sounds for OK deploy process and KO deploy process. Any suggestions? thx

  • http://twitter.com/zack2zack Zack

    awesome :D

  • http://www.jeffwouters.nl Jeff Wouters

    Not sure what you mean… could you drop me an email at contact@jeffwouters.nl with a clear description of what you want to achieve?

  • Jeff Sebrechts

    Nice! Is there also a possibility to play this to remote computers?

  • indigohedgehog

    for($i=200;$i -le 10000; $i+=5){$s=([Math]::Abs([Math]::Cos($i/3.141592)*1000));[console]::Beep($s+30,[Math]::Log($i)*10*[Math]::Abs([Math]::Sin(200))); echo $s}

  • http://www.jeffwouters.nl/ Jeff Wouters

    Now that’s a good one!!!


 Last 50 Posts
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 251
  • Comments » 430
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.

Contact



    No Child Pages.