Counting the Number of Slides in Multiple Presentations


Mike Halpin has posted some very useful PowerShell code to his site which can be used to calculate the number of slides in each PowerPoint file saved to a particular directory. See his posting here. When running the code be sure to exclude his synopsis listed in gray at the beginning. Only use the part posted below.

Open PowerShell ISE (x86) and put the code in the white script pane at the top. Edit the line beginning '$Path = ' to list the folder in which you have saved multiple PowerPoint files. Press F5 to run the script and a chart will be generated in the blue console below listing the name of each presentation and the number of slides in it.

The results look like this:

[CmdletBinding()] [Alias()] [OutputType([psobject])] Param( # The folder containing the files to count [Parameter(ValueFromPipelineByPropertyName=$true, Position=0)] $Path = 'C:\FooFolder\ppts' ) Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName Office Add-Type -AssemblyName Microsoft.Office.Interop.Powerpoint Write-Verbose "Getting files from $path" $files = Get-ChildItem -filter *.ppt* -Path $Path [psobject]$NumberOfSlides= @() Foreach ($file in $files){ $application = New-Object -ComObject powerpoint.application Write-Verbose "Opening $file" $presentation = $application.Presentations.open($file.fullname) $slideCount = New-Object System.Object $slideCount | Add-Member -type NoteProperty -name Name -value $file.name $slideCount | Add-Member -type NoteProperty -name Slides -value $presentation.Slides.Count #Introduce a slight wait so powerpnt.exe has time to process file Start-Sleep -Seconds 2 $presentation.Close() $NumberOfSlides += $slideCount } $NumberOfSlides Write-Verbose "Cleaning up processes" get-process powerpnt | Stop-Process


Contact Me With Your Litigation Support Questions:

seankevinoshea@hotmail.com

  • Twitter Long Shadow

© 2015 by Sean O'Shea . Proudly created with Wix.com