Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName Office
Add-Type -AssemblyName Microsoft.Office.Interop.Powerpoint
#Getting Error - Add-Type -AssemblyName Office Microsoft.Office.Interop.Powerpoint.Slide.SlideShowTransition.Hidden
Function RunSlide {
$pptx = "h:\Test.ppt"
$osld = "Slide"
[bool] $sldState = "Slide.SlideShowTransition.Hidden"
$state = "False"
$hiddenCount = 0
$cc = 0
$application = New-Object -ComObject powerpoint.application
$presentation = $application.Presentations.open($pptx)
$count = 1
Start-Sleep -Seconds 3
ForEach ($osld In $Presentation.Slides)
{
$cc = $cc + 1
If ($sldState -eq "False") {$hiddenCount = $hiddenCount + 1; Write-Host "Slide State $sldState"}
Write-Host "Hidden Count is $hiddenCount"
$endCount = $presentation.Slides.Count
Write-Host "Total slide count is $endCount"
#Present Slide Show
[System.Windows.Forms.SendKeys]::SendWait("{F5}")
do
{
Start-Sleep -Seconds 6
[System.Windows.Forms.SendKeys]::SendWait("{RIGHT}")
$count = $count + 1
Write-Host "Slide Count is $count"
}
while ($count -le $endCount)
Write-Host "POWER POINT RESTARTING"
Stop-Process -processname POWERPNT
}
$b -eq 1
do {
$d = Get-Date
Write-Host "Slide ran as at $d"
CheckSlide
RunSlide
Start-Sleep -Seconds 3
}
While ($b = 1)
So I'm restricted to using powershell (new work policy) and thus am adapting our existing wscript and vbscript files to Powershell.
We have an info wall that uses a hyperlink to a powerpoint presentation. It gets updated regularly so it needs to open, present then close and reopen.
So far I've managed to make this happen. But because of the amount of hidden slides and the nature of my code the script will sometimes run far longer than it has too (sometimes up to 40 slides).
My script checks if the POWERPOINT process is running, if not then it continues and opens the file. Then it will it do a slide count, and run the presentation for the length of the presentation (adds count until it reaches total).
Once finished it will stop the process and the Do loop at the bottom will open the file again. Rinse repeat.
The problem is, is that the Total slide count also counts hidden slides.
What I'm trying to achieve with a ForEach loop is for the script to look at each slide state, if hidden it adds to a count. This count is subtracted from the total and the Do loop uses this count to then present the correct amount of shown slides. Right now the ForEach loop is just reporting the count, not subtracting (because I can't get it to count the hidden amount yet)
I realise there maybe simpler methods for presentation but the translation from Vb to PS has done my head in, it's just plain not working! Getting some tunnel vision and the limited internet access we have is also hindering progress. If anyone can have a look and tell what's redundant and what I maybe missing that would be greatly appreciated. Thank you,