Hi everyone,
I’m hitting a bit of a wall here in my internet research, so I need some help.
I’m a total noob at Powershell and even though I used to code when I was younger this ship has sailed long ago.
What I want to achieve is the following:
I’ve got a Sharepoint site with a powerpoint presentation in it. That presentation runs on various laptops on different sites. I need to be able to change the presentation without having to go to each location or have someone there do it for me.
What I’ve come up with so far is a first script that monitors if a file is dumped in a subfolder called New. When it occurs, it stops Powerpoint. Then I’ve got another script that monitors when a file is created in the main folder and then starts the presentation.
So what happens is: I have a file Pres.ppsx in the folder. I dump NewPres.ppsx in \New, deletes Pres.ppsx and then (in \New) rename NewPres in Pres then Copy and Paste it in the main folder. Still following ?
I thought that would do the trick. However it does not really see the file rename. In addition, the first script seems to halt after it has performed its shutdown action. And cherry on top, when it starts the presentation it sometimes does it 3 times.
So I’m wondering if there’s a better and more clever solution to do this.
Thanks a lot.
Script 1:
SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\FullPath\New"
$watcher.Filter = "*.ppsx"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
DEFINE ACTIONS AFTER A EVENT IS DETECTED
$action = {$pp = [Runtime.Interopservices.Marshal]::GetActiveObject('powerpoint.application')
$pp.Presentations | % {
$_.Save()
$_.Close()
}
# Kill off all PowerPoint apps
Get-Process | ?{$_.ProcessName -eq "POWERPNT"} | Stop-Process
DECIDE WHICH EVENTS SHOULD BE WATCHED (We want PPT to be killed when a new ppsx is dropped in the folder)
$created = Register-ObjectEvent $watcher "Created" -Action $action
#$changed = Register-ObjectEvent $watcher "Changed" -Action $action
#$deleted = Register-ObjectEvent $watcher "Deleted" -Action $action
#$renamed = Register-ObjectEvent $watcher "Renamed" -Action $action
while ($true) {sleep 5}
Script 2:
SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\FullPath"
$watcher.Filter = "*.ppsx"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
DEFINE ACTIONS AFTER A EVENT IS DETECTED
$action = {
# Add entry in the log - Not necessary but helps me understand what happens
$path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Add-content "C:\PS1\log.txt" -value $logline
# Opens the slideshow defined as pptx
$pptx = "C:\FullPath\FrontDesk.ppsx"
$application = New-Object -ComObject powerpoint.application
$presentation = $application.Presentations.open($pptx)
$application.visible = "msoTrue"
$presentation.SlideShowSettings.Run()
}
DECIDE WHICH EVENTS SHOULD BE WATCHED (We want PPT to start with $pptx when $pptx has changed)
$created = Register-ObjectEvent $watcher "Created" -Action $action
#$changed = Register-ObjectEvent $watcher "Changed" -Action $action
#$deleted = Register-ObjectEvent $watcher "Deleted" -Action $action
#$renamed = Register-ObjectEvent $watcher "Renamed" -Action $action
while ($true) {sleep 5}