Control Media Player from PowerShell

by Feb 10, 2011

Start your day with your favorite music or playlist by controlling Media Player by PowerShell.
Get-MediaPlayerItems will return all playlists and multimedia items accessible. Start-MediaPlayer accepts any one of them and will launch Media Player to play the song or playlist:

function Start-MediaPlayer {
param(
[Parameter(Mandatory=$true)]
$name
)

$player = new-object -com WMPLAYER.OCX
$item = $player.mediacollection.getByName($name)
if ($item.Count -gt 0) {
$filename = $item.item(0).sourceurl
$player.openplayer($filename)
} else {
"'$name' not found."
}
}

function Get-MediaPlayerItems {
$player = new-object -com WMPLAYER.OCX
$items = $player.mediacollection.getAll()
0..($items.Count1) | ForEach-Object { $items.Item($_).Name }
}

Twitter This Tip!
ReTweet this Tip!