This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
Using MSH to Manage Your Music Files and Playlists,
I'm a big fan of the MS Scripting Guy's
You Might have seen that they have opened a MSH portal on the ScriptCenter also.
http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspxGreat !!, there are already a couple of sample scripts and an item about WMI in MSH
But also the other Articles a still of interest if you work with MSH, as the most are easy to translate, for Example :
I stole the Title and Subtitle from the following Scripting Guys Article.
http://www.microsoft.com/technet/scriptcenter/funzone/player.mspxIt's about Scripting the Windows MediaPlayer, and did the same in MSH.
(It's also nice to see that MSH works that much easier ;-))I wil show you some examples below but as the article is exelent for the explanation I point you to the article, the examples will get you going doing it the Monad way.
First a Function to play a Playlist in Mediaplayer from MSH like this :
MSH> play-list maddness
the Playlist Function is just this.
function Play-List ([string]$name) {
$WMP = new -com "WMPlayer.OCX"
$wmp.openplayer($wmp.mediaCollection.getByName($name).item(0).sourceURL)
}
And already Monad is Rocking ;-)
But there is More :
The Maddness playlist I created also from MSH, I added all MP3's from a directory,
Created the Playlist , all from the Monad CLI.
Also the are some searching examples below.
More Samples :
# Make a MediaPlayer Object
$WMP = new -com "WMPlayer.OCX"
# get Media Collection
$mc = $WMP.mediaCollection
# get All Items in the Media Collection
$m = $mc.getall()
0..($m.count - 1) | foreach {"$_ $($m.item([int]$_).name)"}
# get only the Audio Items :
$List = MC.getByAttribute("MediaType", "Audio")
0..($list.count - 1) | foreach {"$_ $($list.item([int]$_).name)"}
# List With Duration
0..($list.count - 1) | foreach {$list.item([int]$_)} | ft name,durationstring
# Get Other Atributes
$list.item(25).getItemInfo("AlbumID")
$list.item(25).getItemInfo("Name")
# list all available atributes :
0..($list.item(25).attributeCount - 1) | foreach {$list.item(25).getAttributeName($_)}
# play the File in Mediaplayer
$wmp.openplayer($list.item(25).sourceURL)
# Add some Madness Songs
(ls g:\mp3\Madness) | foreach {$mc.add($_.fullname)}
# Make new playlist
$pl = $WMP.playlistcollection.newplaylist("Madness")
# Get all Madness Songs
$Songs = $mc.getByAuthor("Madness")
# add them to the new playlist
0..($songs.count - 1) | foreach {$pl.appendItem($songs.item([int]$_))}
# Open the created songlist
$wmp.openplayer($wmp.mediaCollection.getByName("Madness").item(0).sourceURL)
As said for the most this are just the examples from the original article, and for the most even simpler as in the origional examples, so for the explanation of the $WMP objectI point you there (also use Get-Member a lot as alway's in MSH ;-).
but there is an interesting thing to note on the Monad side in the scripts also.
Maybe you did allready note the foreach loops like this one
0..($m.count - 1) | foreach {"$_ $($m.item([int]$_).name)"}
What happens here is that I use the Foreach as an For Loop.
0..($m.count - 1)
will just make a range of numbers.
so I get all the Items till the last one (as we start with 0, we need 1 less as the count value)
so this :
$m.item([int]$_).name
will get the Item, reason for this is that the Objects are not Array's and They don't have a GetEnumerator() Method, so we can't do a "normal" foreach.
you could also do this with a For loop, but if it's on one line I like this way more as the for loop contructor in MSH is a bit bigger, this would be the same with For :
For ($i = 0 ; $i -lt $m.count ; $i++) {"$_ $($m.item([int]$i).name)"}
In the Scripting Guys article are some more examples, but it's more of the same so this will get you going translating the rest to MSH.
as as said it's a very good read.
Enjoy "Rocking Monad"
greetings /\/\o\/\/