Get your geek on with PowerShell and some music

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)

13 comments

  1. Michael says:

    Thats great 🙂

  2. Tim Bolton says:

    Brilliant..!

  3. lesaboteur says:

    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)

  4. Jeff Wouters says:

    Whahaha! Nice 😀 Thanks for sharing!

  5. kiquenet kiquenet says:

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

  6. Zack says:

    awesome 😀

  7. Jeff Wouters says:

    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?

  8. Jeff Sebrechts says:

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

  9. indigohedgehog says:

    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}

  10. Jeff Wouters says:

    Now that’s a good one!!!

  11. Hiram says:

    Wow!, thanks for sharing, love it.

    so is some native way into powershell to do this?

  12. Jeff Wouters says:

    This is the only way I know of, and the console class can be used in PowerShell and since PowerShell is build on top of .NET I guess this is as native as you can get 😉

  13. TheRedCat says:

    Here’s another version of the Imperial March done in 110 4/4 time. Each space is a new measure. Done in C++

    #include
    #include
    using namespace std;

    void starWars();

    int main()
    {
    starWars();

    system(“pause”);
    return 0;
    }

    void starWars()
    {
    Beep(440, 545);
    Beep(440, 545);
    Beep(440, 545);
    Beep(349, 409);
    Beep(523, 136);

    Beep(440, 545);
    Beep(349, 409);
    Beep(523, 136);
    Beep(440, 1090);

    Beep(659, 545);
    Beep(659, 545);
    Beep(659, 545);
    Beep(698, 409);
    Beep(523, 136);

    Beep(415, 545);
    Beep(349, 409);
    Beep(523, 136);
    Beep(440, 1090);

    Beep(880, 545);
    Beep(440, 409);
    Beep(440, 136);
    Beep(880, 545);
    Beep(831, 273);
    Beep(784, 273);

    Beep(740, 136);
    Beep(698, 136);
    Beep(740, 273);
    Sleep(273);
    Beep(415, 273);
    Beep(554, 545);
    Beep(587, 272);
    Beep(554, 273);

    Beep(523, 136);
    Beep(494, 136);
    Beep(523, 273);
    Sleep(273);
    Beep(349, 273);
    Beep(415, 273);
    Beep(349, 409);
    Beep(415, 136);

    Beep(523, 273);
    Beep(440, 273);
    Beep(523, 273);
    Beep(659, 1090);

    Beep(880, 545);
    Beep(440, 409);
    Beep(440, 136);
    Beep(880, 545);
    Beep(831, 273);
    Beep(784, 273);

    Beep(740, 136);
    Beep(698, 136);
    Beep(740, 273);
    Sleep(273);
    Beep(415, 273);
    Beep(554, 545);
    Beep(587, 272);
    Beep(554, 273);

    Beep(523, 136);
    Beep(494, 136);
    Beep(523, 273);
    Sleep(273);
    Beep(349, 273);
    Beep(415, 545);
    Beep(349, 409);
    Beep(523, 136);

    Beep(440, 545);
    Beep(349, 409);
    Beep(523, 136);
    Beep(440, 1090);

    Sleep(1000);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *