Jan 13 2023 03:32 PM
Hi there
What PowerShell script can replace hyperlinks in an MS PowerPoint document on SharePoint Online, taking old URLs and new URLs from a CSV file?
Thank you.
Feb 02 2023 02:33 AM - edited Feb 02 2023 02:36 AM
Hello @frob009,
You can use Powerpoint COM object and open file directly from SharePoint online and then perform needed manipulations.
Something like this:
Add-type -AssemblyName office
$PowerpointFile = "<SharePoint Online URL to file"
$Powerpoint = New-Object -ComObject powerpoint.application
$ppt = $Powerpoint.presentations.open($PowerpointFile, 2, $True, $False)
$URLMap=Import-Csv .\URLMapping.csv
foreach($slide in $ppt.slides){
foreach ($h in $slide.Hyperlinks){
$NewURL=$URLMap | Where-Object {$_.OldURL -eq $h.Address} | Select -ExpandProperty NewURL
if($NewURL){
Write-Output "Old Url: $($h.Address)"
$h.Address=$NewURL
Write-Output "New Url: $($h.Address)"
}
}
}
Sleep -Seconds 3
$ppt.Save()
Sleep -Seconds 3
$Powerpoint.Quit()
Refences:
Hey, Scripting Guy! How Can I Customize Microsoft PowerPoint Presentations? - Scripting Blog
powershell edit powerpoint slide notes - Stack Overflow
Hope that helps.