Forum Discussion
frob009
Jan 13, 2023Copper Contributor
What PowerShell can replace hyperlinks in a PowerPoint on SharePoint Online, taking URLs from a CSV?
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.
AndySvints
Feb 02, 2023Steel Contributor
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.