Creating Powerpoint Decks with Powershell

A couple days ago I would have been happy to have an automated way of creating Powerpoint slides (Powerpoint was not my choice anyway) now I found one with the help of the Scripting Guy and StackOverflow. The following code just opens Powerpoint and adds a couple slides, each with a different layout. I am not sure (resp. too lazy to check) how many layouts there are but it must be more than 30.

Clear-Host
Add-type -AssemblyName office
$application = New-Object -ComObject powerpoint.application
$application.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
$presentation = $application.Presentations.add()
 
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 1) # title slide
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 2) # slide title and text
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 3)
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 4)
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 5)
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 6)
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 7)
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 8)
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 9)
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 10)
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 11) # just slide title
$slide.Shapes.title.TextFrame.TextRange.Text = "This is the slide title"
$slide = $Presentation.Slides.Add($presentation.Slides.Count + 1, 12) # blank

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website