I got a little bit inspired today.   If you saw an amazing Sharepoint Guru found out how to make Powershell talk by using  NEW-OBJECT and linking to the Speech interface in Windows.

Then all day long in the back of my head I kept thinking, “Now if I could get Powershell to Play Music, I could get it to do Karaoke”.

Yes it was an odd day, which spawned THIS function.  INVOKE-MEDIA

Really it’s no different that any other link to Com Objects.   I create a link to it using a Variable in Powershell and attaching to the Media Player in Windows.  Of course, if you don’t have the Media Player or a sound Card (or a computer for that matter) this will fail miserably.

But all I did to figure it out was

1) Dig into the registry under HKLMSoftwareClasses for what appeared to be the Location of Windows Media Player and Guessed (Turned out to be called “MediaPlayer.MediaPlayer” for the COM name (well THAT wasn’t very creative!)

2) Created a link to it using

$PLAYER=NEW-OBJECT –ComObject ‘MediaPlayer.MediaPlayer’

3) Piped the results into a GET-MEMBER to see what Methods and properties were available.   Turns out quiite a few to understate.

The ones that caught my interest were “FILENAME” (A Property) and “Play” a Method.

So now executing the following new lines


Produced the the “Chimes.Wav” file playing in the background

To write this into a useful function just execute

function global:INVOKE-MEDIA ($Filename) {

$PLAYER=NEW-OBJECT –ComObject ‘MediaPlayer.MediaPlayer’


And to use that function just simply execute

INVOKE-MEDIA ‘C:WindowsMediaChimes.wav’

Or what so ever drives your fancy as a file.

Powershell, It’s easier than it seems

The Energized Tech