PowerShell to find HyperLink Text in PowerPoint

Recently I faced a scenario where I needed to find if a particular url is used in hyperlink in 100s of ppt. Opening ppt and looking for the ppt is cumbersome,  so wrote a small PowerShell to find the url. Here is the PowerShell Script code



$FilePath= "C:\Users\xxx\Path"
Add-Type -AssemblyName Office
$ppt = New-Object -ComObject powerpoint.Application
$DocumentsLib = Get-ChildItem -Path "$FilePath" -Filter "*.ppt*" -Recurse
$Doc = New-Object -ComObject powerpoint.Application

$i=0
$DocumentsLib | ForEach-Object {

Write-Host $_.FullName
$Doc = $ppt.Presentations.Open($_.FullName,$Null,$Null,[Microsoft.Office.Core.MsoTriState]::msoFalse)
$Slides = $Doc.Slides
Foreach ($Slide in $Slides) {
    $Slide.Hyperlinks | ForEach-Object {
       
        if ($_.Address -like "*texttofind*" -or $_.Text -like "texttofind*") 
        {
           write-host $_.Address
           write-host "Found"
            break
        }
               
 }
}
#$Doc.Save()
#$Doc.Close($false)
#$ppt = $null
 Write-Progress -Activity "Searching Hyperlinks" -Status "Progress:" -PercentComplete ($i/$DocumentsLib.count*100)
  $i++
}
[gc]::collect()
[gc]::WaitForPendingFinalizers() 

2 comments:

sindhu said...

Works for me ! great help thanks a lot

Vijay Vishwakarma said...

Happy to help

Running Total In SQL Server

Running total refers to the sum of values in all cells of a column that precedes the next cell in that particular column. Using Window Funct...