/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Passing (not so) mandatory Parameters to WMI metho... "," Saving a WMI instance to a XML-file from MSH "," MSH Orphan share remover Tool "," MSH Welcome screen "," Read the raw Monad XML helpfiles "," MSH prompt-User function with Help "," Monad IRC Bot "," Getting performanceMonitor info from Monad "," Monad -and More bytes with -band = shorter script "," Tip from Monad "," ")

Thursday, December 22, 2005

 


Monad Really Does Rock



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.mspx
Great !!, 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.mspx

It'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\/\/


Comments: Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?