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 ![]()
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
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)

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 