Listing Your Media Collection

by Mar 2, 2009

Windows Media Player (WMP) gives you access to all of your media stored on your computer. PowerShell can access this information through COM using New-Object with the -COMObject parameter. Windows Media Player uses WMPLAYER.OCX as its ProgID:

$player = new-object –COM WMPLAYER.OCX
$all = $player.mediaCollection.getAll()
0..$($all.count-1) | ForEach-Object { $all.Item($_) }

This will get you all media organized by WMP. You can also access the WMP object model in $player to retrieve media by name, genre or album. To retrieve all audio playlists, do this:

$player.mediaCollection.getByAttribute("MediaType", "audio")

Other attribute values are "playlist", "radio", "video", "photo" and "other".

$all = $player.mediaCollection.getByAttribute("MediaType", "playlist")
0..$($all.count-1) | ForEach-Object { $all.Item($_) }