I was looking at the referring searches which forwarded people to my blog and noticed several hits for ‘powershell beep’. I previously used Console.Beep in a post where you can make different frequency’s of beeps but there are also some ‘canned’ Windows sounds called System Sounds which you can call. When you hear them, I’m sure you will recognize them. I made a small script to demonstrate them. They could be used as audio cues to standard responses or warnings in PowerShell scripts. The sounds are easily called with one-liners.

They are in the System.Media Namespace called the SystemSounds Class. There are 5 of them – Asterisk, Beep, Exclamation, Hand and Question. Question did not a make a sound on my system, it may not be used in my Windows Sound Scheme. I included it because it is still listed as a valid property, but it may not work on all systems.

In a simple WinForms Form you selelct a sound using a RadioButton. The sounds are called using the play method of the sounds property in the SystemSounds class.

Add-Type -AssemblyName System.Windows.Forms

# Main Form and Objects
$mainForm = New-Object Windows.Forms.Form
$mainForm.Font = "Comic Sans MS,9"
$mainForm.Text = "System Sounds"
$mainForm.size = "400,300"

# Asterisk Sound
$radioButtonAsterisk = New-Object System.Windows.Forms.RadioButton
$radioButtonAsterisk.Location = "40,40"
$radioButtonAsterisk.Text = "Asterisk"
$radioButtonAsterisk.add_Click({
    [System.Media.SystemSounds]::Asterisk.Play()
    })
$mainForm.Controls.Add($radioButtonAsterisk)

# Beep Sound
$radioButtonBeep = New-Object System.Windows.Forms.RadioButton
$radioButtonBeep.Location = "40,80"
$radioButtonBeep.Text = "Beep"
$radioButtonBeep.add_Click({
    [System.Media.SystemSounds]::Beep.Play()
    })
$mainForm.Controls.Add($radioButtonBeep)

# Exclamation Sound
$radioButtonExclamation = New-Object System.Windows.Forms.RadioButton
$radioButtonExclamation.location = "40,120"
$radioButtonExclamation.Text = "Exclamation"
$radioButtonExclamation.add_Click({
    [System.Media.SystemSounds]::Exclamation.Play()
    })
$mainForm.Controls.Add($radioButtonExclamation)

# Hand Sound
$radioButtonHand = New-Object System.Windows.Forms.RadioButton
$radioButtonHand.Location = "40,160"
$radioButtonHand.Text = "Hand"
$radioButtonHand.add_Click({
    [System.Media.SystemSounds]::Hand.Play()
    })
$mainForm.Controls.Add($radioButtonHand)

# Question Sound
$radioButtonQuestion = New-Object System.Windows.Forms.RadioButton
$radioButtonQuestion.Location = "40,200"
$radioButtonQuestion.Text = "Question"
$radioButtonQuestion.add_Click({
    [System.Media.SystemSounds]::Question.Play()
    })
$mainForm.Controls.Add($radioButtonQuestion)

# Display Form
[void] $mainForm.ShowDialog()

SystemSounds

SystemSounds.ps1

Advertisements