Last active
April 29, 2020 15:58
-
-
Save JTBrinkmann/d19292d582ce9c01bd7328f8b5009b8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string] $inFilePath, | |
[string] $outFilePath = $false | |
) | |
# older PowerPoint versions don't support exporting to MP4 (e.g. 2010) | |
# use WMV as fallback and if necessary convert via ffmpeg (not part of this script) | |
if ([Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsMP4) { | |
$outExt = "mp4" | |
$outExtType = [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsMP4 | |
} else { | |
$outExt = "wmv" | |
$outExtType = [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsWMV | |
} | |
$inFile = gci $inFilePath | |
if ($outFilePath -eq $false) { | |
$outFile = "$($inFile.Directory.FullName)\$($inFile.BaseName).$outExt" | |
} else { | |
$outFile = $outFilePath | |
} | |
echo "converting '$inFile' => '$outFile'" | |
$Application = New-Object -ComObject powerpoint.application | |
$Application.Visible = [Microsoft.Office.Core.MsoTriState]::msoTrue | |
$Presentation = $Application.Presentations.Open($inFile.FullName) | |
$Presentation.SaveAs($outFile, $outExtType) | |
# wait until finished | |
while ($Presentation.CreateVideoStatus -eq 1) { | |
sleep 0.5 | |
} | |
$Presentation.Close() | |
$Application.Quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment