To catch a user’s attention, your script can easily play WAV sound files. Here is a simple function:- function Play-Alarm {
- $path = "$PSScriptRoot\Alarm06.wav"
- $playerStart = New-Object Media.SoundPlayer $path
- $playerStart.Load()
- $playerStart.PlaySync()
- }
复制代码 It assumes the WAV file is located in the same folder the script is saved in. Note that $PSScriptRoot is not supported in PowerShell 2.0.
Just make sure you rename the $path variable and have it point to any valid WAV file you want to use.
By default, PowerShell will wait until the sound is played. Replace PlaySync() with Play() if you want PowerShell to continue and not wait.
http://powershell.com/cs/blogs/tips/archive/2014/01/29/playing-a-sound-on-error.aspx |