As the title states, I have a .bat
job running within PowerShell that when finished running, I would like a sound notification to go off. I was wondering if there was a PowerShell command that I can add to my existing PowerShell command.
How to play a sound file from a Windows batch file. Use the start command to start the program associated with the file. For example, if you wanted to open the player to play "music.mp3" in the command line or batch file, you could type the below command.
Is there a way in Windows PowerShell to do this? You sure can! Using the System.Media.Soundplayer object, you can do this quite easily. Here is an example of how to do this: Comments are closed. Login to edit/delete your existing comments
Some PowerShell scripts take a long time to run. I have, on occasion, built scripts that took upwards of 20 minutes to execute. For long-running scripts, it can be handy to get PowerShell to play a sound when the script completes.
The Windows Media Player can run from the command line, or in a batch file, to play sound files. In Windows 10, the Media Player executable file is located at Program Files (x86)\Windows Media Player\wmplayer.exe. In previous versions of Windows, the Media Player executable was named mplay32.exe or mplayer.exe.
Besides the excellent solutions of boxdog (here) and TheGameiswar (here), I want to mention another possibility, which lets you play some standard system sounds:
[System.Media.SystemSounds]::Asterisk.Play()
[System.Media.SystemSounds]::Beep.Play()
[System.Media.SystemSounds]::Exclamation.Play()
[System.Media.SystemSounds]::Hand.Play()
[System.Media.SystemSounds]::Question.Play()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With