PowerShell – Play Alert or Sound

email me

# play alert sound
$sound = new-Object System.Media.SoundPlayer;
$sound.SoundLocation="c:\WINDOWS\Media\notify.wav";
$sound.PlayLooping();
$flag=$false;
 
1..10 | foreach {
    if($_ -gt 1){$flag=$true} else{sleep -s 1}
    if($flag) {$sound.Stop() }
}