PowerShell Script to Autoplay WMP Playlist
We have an old workstation connected to our PBX that suffices as our music on hold media player. During the month of December, this Windows XP box plays music from a holiday play list. Here’s a little batch file that utilizes PowerShell and Windows Media Player play lists to automate this task.
Logon Script
@ECHO OFF IF "%date:~-10,2%" == "12" GOTO DECEMBER IF NOT "%date:~-10,2%" == "12" GOTO GENERALECEMBER %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\December.ps1 GOTO END :GENERAL %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\General.ps1 GOTO END :END
General.ps1
$WMP = New-object –COM WMPlayer.OCX $WMP = new-object –COM WMPLAYER.OCX $Media = $WMP.mediacollection $strplaylist = "General" $WMP = new-object –COM WMPLAYER.OCX $Media = $WMP.mediacollection $Playlist = $media.getbyname($strplaylist) $a = $Playlist.item(0) $WMP.openplayer($a.sourceurl)
December.ps1
$WMP = New-object –COM WMPlayer.OCX $WMP = new-object –COM WMPLAYER.OCX $Media = $WMP.mediacollection $strplaylist = "December" $WMP = new-object –COM WMPLAYER.OCX $Media = $WMP.mediacollection $Playlist = $media.getbyname($strplaylist) $a = $Playlist.item(0) $WMP.openplayer($a.sourceurl)
I put each of the scripts in the root of C. Then I simply configured the server to reboot every night at midnight and auto-logon. When the computer reboots, it logs in, runs the login script, checks the current month and then loads the appropriate playlist.

