mike szokola
mike szokola

Reputation: 11

Having issues making a simple script in powershell run windows media player in the background

I am trying to do a simple script to where I only want a portion of my script to run in the background. I want to run the windows media player in the background. I am brand new to powershell and scripting in general, having a whole day and a half under my belt. Can someone help me out and explain in basic terms how the start job works with invoke-item. Thank you for any help you can provide.

Here is my original script. I wanted to launch a powerpoint and have my media player come up a little after I got it to load. I realize I could do this in powerpoint, but I am using it to try and learn. I got this to work:

#Call SSD
$MusicPath = "C:\powershell\Windows_Exclamation.wav"    
$Powerpoint = "C:\powershell\SSD.ppsx"     
invoke-item $Powerpoint    
start-sleep -s 3    
invoke-item $MusicPath 

I wanted the media player to run in the background. Here is my script so far:

#Call SSD
$MusicPath = "C:\powershell\Windows_Exclamation.wav"    
$Powerpoint = "C:\powershell\SSD.pptx"     
invoke-item $Powerpoint    
start-sleep -s 3    
start-job -scriptblock {invoke-item} $MusicPath 

Should I be using invoke-command or am I just lost in the sauce here?

Upvotes: 1

Views: 480

Answers (1)

Knuckle-Dragger
Knuckle-Dragger

Reputation: 7046

I'd use a media.soundplayer object.

$MusicPath = "C:\Windows\Media\Windows Exclamation.wav"    
Function PlayWav($path){(new-object Media.SoundPlayer "$path").play();}
PlayWav -Path "$MusicPath"

Upvotes: 1

Related Questions