Playing WAV files

by Feb 13, 2013

PowerShell can play WAV files, so you can add sound and special effects to your scripts (provided your system has a sound card):

PS> $player = New-Object System.Media.SoundPlayer "$env:windir\Media\notify.wav"
PS> $player.Play()

You can also use this as sort of an acoustic progress bar because the sound plays in a separate thread and won't block PowerShell. So a script could repeat some sound until the task is done, then stop the sound:

PS> $player.PlayLooping()
PS> # do some lengthy job
PS> $player.Stop()

Note: The SoundPlayer object can play sounds in WAV format only, so if you'd like to play your favorite song or record some voice message, make sure you use this format.

Twitter This Tip! ReTweet this Tip!