Playing a Song with Media Player

by Mar 3, 2009

Windows Media Player can be accessed using COM, and WMP in turn gives you access to your entire media. Using GetByName(), you can directly access media by name and have WMP play the media:

$name = read-host "Enter media name/song name/playlist name"
$player = new-object -com WMPLAYER.OCX
$item = $player.mediacollection.getByName($name)
if ($item.Count -gt 0) {
$filename = $item.item(0).sourceurl
"Playing $filename"
$WMP.openplayer($filename)
} else {
"'$name' not found."
}

You could add this to your profile script so powershell will let you play your favorite playlist when you start your day.