Files

27 lines
1.1 KiB
PowerShell

param(
[Parameter(Mandatory=$true)][string]$Src,
[Parameter(Mandatory=$true)][string]$Out
)
# Convert .ppt (legacy) to .pptx via PowerPoint COM, then quit.
# Usage: powershell -File convert_ppt.ps1 -Src "D:\...\xxx.ppt" -Out "D:\...\xxx.pptx"
# Never modifies the source file (opened ReadOnly). Output format 24 = ppSaveAsOpenXMLPresentation.
$ErrorActionPreference = 'Stop'
$ppt = $null
$pres = $null
try {
$ppt = New-Object -ComObject PowerPoint.Application
$pres = $ppt.Presentations.Open($Src, $true, $false, $false)
$pres.SaveAs($Out, 24)
$pres.Close()
Write-Output ("OK: " + $Out)
} catch {
Write-Error ("Convert failed: " + $_.Exception.Message)
exit 1
} finally {
if ($null -ne $pres) { try { $pres.Close() } catch {} }
if ($null -ne $ppt) { try { $ppt.Quit() } catch {} }
if ($null -ne $pres) { try { [void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($pres) } catch {} }
if ($null -ne $ppt) { try { [void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($ppt) } catch {} }
[GC]::Collect(); [GC]::WaitForPendingFinalizers()
}