Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get Windows PowerShell to play a sound after .bat job has finished running?

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.

like image 503
harcot Avatar asked May 08 '19 01:05

harcot


People also ask

How to play a sound file from a Windows batch file?

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 make a sound player?

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

How long does it take for a PowerShell script to run?

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.

How do I play sound files on Windows 10?

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.


1 Answers

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()
like image 112
stackprotector Avatar answered Nov 17 '22 01:11

stackprotector