Text searching a Powerpoint document for a string

I haven't found any good examples of how to text search a powerpoint document.    I have something like this working for word and excel documents but having a problem with shapes in powerpoint.

I believe I must find the number of slides and walk them... then within that determine the number of shapes on each slide and walk them.  On shapes that are of type text I need to search for a string.

I am stuck on determining the number of shapes on a slide.   I can put the .ppt and .pptx files in a collection, put the slides for each file in a collection and walk it, but I have a problem figuring out the number of shapes and putting them in a collection to walk.  

My goal is to find the number of shapes of type text and then search it for a string.   

I am using office (powerpoint) 2007, & Win7 x64.  

Any help getting past the shapes problem would be most appreciated.

This is what I have pieced together so far from using other examples I have seen...

# Search Powerpoint for a text string
Add-type -AssemblyName office
Add-type -AssemblyName microsoft.office.interop.powerpoint

$path = "C:\test1"
$MatchString = "one"
$pptSlides = Get-Childitem -Path $path -Include *.ppt,*.pptx -Recurse

# Create instance of the PowerPoint.Application COM object
$ppt = New-Object -ComObject PowerPoint.Application
#$ppt.Activate()

# possibly many PowerPoint files in the folder so to stop PowerPoint app from appearing and disappearing
#$ppt.visible = $false
#$ppt.visible="msoTrue"
$ppt.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue

# walk through the collection of slides
foreach($pptSlide in $pptSlides)
{

 write-host $pptSlide
 $presentation = $ppt.Presentations.open($pptSlide)

 # Max slides is determined for slide one
 $slcount = $ppt.ActivePresentation.Slides.Count 
 Write-Host "Total Slides = $slcount"

 ######################################
 #  Seems to be good to here
 ######################################

 # Max shapes is determined on just slide one.. as a test... this does not work
 $shcount = $ppt.ActivePresentation.Slides(1).Shapes.Count
 Write-Host "Total Shapes on Slide 1 = $shcount"

 # Walk through the collection of shapes

# not certain what to do here.   could maybe use $shcount if I could populate that
 ForEach($pptShape in $ppt.ActivePresentation.Slides($slcount).Shapes) {
     # trying to determine the shape type - want those of type text

     Write-Host $pptShape.Type
     # if type text then search for text goes here

     # if type is a spreadsheet then search for text - nice to have - may skip this
 }


 # prevent the Save Presentation prompt from displaying
 $presentation.saved = $true
 # close presentation
 $presentation.close()
 
 } #end for
 
 
 # release memory
 $ppt.quit()
 # release the memory immediately
 $ppt = $null
 # call garbage collection
 [gc]::collect()
 [gc]::WaitForPendingFinalizers()

Parents
No Data
Reply
  • Not exactly what you are trying to achieve but I want to compare content of two ppt so I use your work to give it a try and I am successfull to fetch the data. you can modify it to search string as well:

    $shcount = $null# Search Powerpoint for a text string
    Add-type -AssemblyName office
    Add-type -AssemblyName microsoft.office.interop.powerpoint

    $path = "C:\Users\kshsha01\Downloads\newfolder\testing\presentation1.pptx"
    $MatchString = "one"
    $pptSlides = Get-Childitem -Path $path -Recurse

    # Create instance of the PowerPoint.Application COM object
    $ppt = New-Object -ComObject PowerPoint.Application
    #$ppt.Activate()

    # possibly many PowerPoint files in the folder so to stop PowerPoint app from appearing and disappearing
    #$ppt.visible = $false
    #$ppt.visible="msoTrue"
    $ppt.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue

    # walk through the collection of slides
    foreach($pptSlide in $pptSlides)
    {

    write-host $pptSlide
    $presentation = $ppt.Presentations.open($pptSlide)

    # Max slides is determined for slide one
    $slcount = $ppt.ActivePresentation.Slides.Count
    Write-Host "Total Slides = $slcount"
    $e = $slcount
    $i = 0
    while($i -ne $e)
    {$i++

    $test = $ppt.ActivePresentation.Slides($i).Shapes.count
    $testo = $ppt.ActivePresentation.Slides($i).Shapes
    $x = 0
    while($x -ne $test){
    $x++
    foreach($d in $testo){
    if($d.HasTextFrame -ne $null)
    {$ppt.ActivePresentation.Slides($i).Shapes($x).Name
    $ppt.ActivePresentation.Slides($i).Shapes($x).TextFrame.TextRange.Text}
    }}}}

Children
No Data