Last active
August 11, 2026 20:47
-
-
Save jcoehoorn/6a8280cc83b1481d569e326af5c83cbb to your computer and use it in GitHub Desktop.
PPTtoPPTX.ps1
This file contains hidden or 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
| <# | |
| .SYNOPSIS | |
| Converts legacy PowerPoint (.ppt) files to OpenXML presentation (.pptx) format. | |
| .DESCRIPTION | |
| Searches a specified directory for legacy .ppt files and converts them to .pptx using | |
| Microsoft PowerPoint COM automation. Displays a progress dot indicator for large | |
| batches (>150 files) unless -Verbose is enabled. | |
| .PARAMETER Path | |
| The target directory containing .ppt files. Defaults to the script's execution directory ($PSScriptRoot). | |
| .PARAMETER Recurse | |
| If specified, searches subdirectories recursively for .ppt files. Defaults to $false. | |
| .PARAMETER Replace | |
| If specified, deletes the original .ppt file after a successful conversion. Defaults to $false. | |
| .EXAMPLE | |
| .\Convert-PPT.ps1 | |
| Converts all .ppt files in the script's local folder to .pptx. | |
| .EXAMPLE | |
| .\Convert-PPT.ps1 -folderPath "C:\Slides" -Recurse -Replace -Verbose | |
| Recursively processes C:\Slides, replaces original .ppt files upon success, and logs each file to the console. | |
| #> | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter(Position = 0)] | |
| [string]$Path = $PSScriptRoot, | |
| [switch]$Recurse = $false, | |
| [switch]$Replace = $false | |
| ) | |
| # Ensure MS Office (PowerPoint) is available | |
| $pptProgId = [Type]::GetTypeFromProgID("PowerPoint.Application") | |
| if (-not $pptProgId) { | |
| Write-Error "Microsoft PowerPoint is not detected on this system. Please install Microsoft Office/PowerPoint to run this script." | |
| return | |
| } | |
| # Ensure folder exists | |
| if (-not (Test-Path -Path $Path)) { | |
| Write-Error "Target folder does not exist: $Path" | |
| return | |
| } | |
| # Retrieve .ppt files (recurse conditionally based on $Recurse) | |
| $pptFiles = Get-ChildItem -Path $Path -Filter "*.ppt" -Recurse:$Recurse | Where-Object { $_.Extension -ieq ".ppt" } | |
| $totalCount = $pptFiles.Count | |
| if ($totalCount -eq 0) { | |
| Write-Host "No .ppt files found in $Path" | |
| return | |
| } | |
| # Explicitly check if -Verbose flag was passed or $VerbosePreference was enabled | |
| $isVerbose = $PSBoundParameters.ContainsKey('Verbose') -or ($VerbosePreference -ne 'SilentlyContinue') | |
| $showDots = (-not $isVerbose) -and ($totalCount -gt 150) | |
| # Initialize PowerPoint Application | |
| $pptApp = New-Object -ComObject PowerPoint.Application | |
| $saveFormat = 24 # ppSaveFormatOpenXMLPresentation (.pptx) | |
| try { | |
| $currentIndex = 0 | |
| foreach ($file in $pptFiles) { | |
| $currentIndex++ | |
| $pptxPath = [System.IO.Path]::ChangeExtension($file.FullName, ".pptx") | |
| # 1. Check for existing PPTX file | |
| if (Test-Path -Path $pptxPath) { | |
| if ($showDots -and $currentIndex -gt 1) { Write-Host "" } # Break dot line before warning | |
| Write-Warning "Skipping '$($file.Name)': PPTX file already exists." | |
| continue | |
| } | |
| # 2. Output Verbose info or calculate progress dots | |
| if ($isVerbose) { | |
| Write-Host "Processing [$currentIndex/$totalCount]: $($file.FullName)" | |
| } elseif ($showDots) { | |
| $previousDots = [math]::Floor((($currentIndex - 1) / $totalCount) * 50) | |
| $currentDots = [math]::Floor(($currentIndex / $totalCount) * 50) | |
| if ($currentDots -gt $previousDots) { | |
| Write-Host "." -NoNewline | |
| } | |
| } | |
| # 3. Convert PPT to PPTX | |
| try { | |
| $pres = $pptApp.Presentations.Open($file.FullName, [Microsoft.Office.Core.MsoTriState]::msoTrue, $null, [Microsoft.Office.Core.MsoTriState]::msoFalse) | |
| $pres.SaveAs($pptxPath, $saveFormat) | |
| $pres.Close() | |
| if ($Replace) { | |
| Remove-Item -Path $file.FullName -Force | |
| } | |
| } catch { | |
| if ($showDots) { Write-Host "" } | |
| Write-Error "Failed to process '$($file.Name)': $_" | |
| } | |
| } | |
| if ($showDots) { Write-Host "" } | |
| } finally { | |
| $pptApp.Quit() | |
| [System.Runtime.InteropServices.Marshal]::ReleaseComObject($pptApp) | Out-Null | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment