Create mp4 from PowerPoint in PowerShell

1

I'm working on a project that requires automation of a PowerPoint presentation export to a .mp4 format. I've figured out how to save a PowerPoint in the .mp4 format using powershell, but I have not been able to find any documentation on how to change the amount of seconds the slides remain on screen in the video using only powershell.

Current Code:

$Application = New-Object -ComObject powerpoint.application
$Application.Visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
$ThemePath = "C:\Users\Theme.potx"
$PPTXPath = "C:\Users\ExistingPresentation.pptx"
$SavePath = "C:\Users\MyPresentation.mp4"

$Presentation = $Application.Presentations.Open($ReportPath)
--Applies a theme for the slides
$Presentation.ApplyTemplate($ThemePath)
--Saves as a Video
$Presentation.SaveAs($SavePath, 39)
$Presentation.Close()

What I'm trying to target:

Target

EDIT: I've found a library within Windows PowerPoint that seems to contain a library of Classes that can be used to alter its members. One of the is "powerpoint.application," the following script should theoretically be possible per what Theo has suggested, though I get an error instead.

$SlideShowTransition = New-Object -ComObject powerpoint.SlideShowTransition
$SlideShowTransition.AdvanceOnTime = $True
$SlideShowTransition.AdvanceTime = 10

New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not 
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:1 char:13
+ $Whatever = New-Object -ComObject powerpoint.SlideShowTransition
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

Here is another screenshot directly from the environment. For some reason, SlideShowTransition isn't showing up. I may be missing a reference...?

powershell
powerpoint
asked on Stack Overflow Dec 7, 2018 by AngryDev • edited Dec 7, 2018 by AngryDev

1 Answer

0

I think you shouldn't create $SlideShowTransition without using $Presentation because the latter represents the actual presentation, without that you can't set anything on it.
See the example on MS official doc how it uses ActivePresentation to do the setting.
How it works: if you search for ActivePresentation in the left search box, you see that it is under Application. So to refer to it the path is Application.ActivePresentation.Slides and after you can try Theo's method. I think as you have only 1 presentation open that is the active one. If not you need to dig more in the docs to activate your $Presentation.

answered on Stack Overflow Dec 7, 2018 by Dávid Laczkó • edited Dec 7, 2018 by Dávid Laczkó

User contributions licensed under CC BY-SA 3.0