Created
February 22, 2022 14:18
-
-
Save haggaie/83ae03822f20fdc1cd54826688189d49 to your computer and use it in GitHub Desktop.
Extract notes text from PowerPoint slides in PowerShell
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
$ErrorActionPreference = "Stop" | |
# Usage: extract-notes.ps1 <file> | |
$Filename = $args[0] | |
$Output = 'notes.md' | |
$Enc = 'Unicode' | |
Write-Host "Opening filename: '$Filename'" | |
Add-type -AssemblyName office | |
# Open Powerpoint slides | |
$Application = New-Object -COM "PowerPoint.Application" | |
$Application.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue | |
$Presentations = $Application.Presentations | |
$Presentation = $Presentations.Open($Filename, 1) | |
# Get sections | |
$Sections = $Presentation.SectionProperties | |
$NumSections = $Sections.Count | |
$name = $Sections.Name | |
Write-Host "$NumSections sections; name = $name" | |
Clear-Content $Output | |
# Iterate sections | |
For ($SectionIndex = 1; $SectionIndex -le $Sections.Count; $SectionIndex++) { | |
$SectionName = $Sections.Name($SectionIndex) | |
Write-Host "# $SectionName" | |
Add-Content $Output "`n# $SectionName`n" -Encoding $Enc | |
for ($SlideIndex = 0; $SlideIndex -lt $Sections.SlidesCount($SectionIndex); $SlideIndex++) { | |
$Index = $Sections.FirstSlide($SectionIndex) + $SlideIndex | |
$Slide = $Presentation.Slides($Index) | |
# Add-Content $Output "$Index`n" -Encoding $Enc | |
Add-Content $Output "" -Encoding $Enc | |
# Get notes from slide | |
$Slide.NotesPage.Shapes | ForEach-Object { | |
if ($_.PlaceholderFormat.Type -eq 2 -and $_.HasTextFrame) { # ppPlaceholderBody | |
$TextFrame = $_.TextFrame | |
if ($TextFrame.HasText) { | |
$Text = $TextFrame.TextRange.Text -replace "\[click\]", "" | |
Add-Content $Output $Text -Encoding $Enc | |
} | |
} | |
} | |
} | |
} | |
$Presentation.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment