Tuesday, May 29, 2012

Using Powershell to change powerpoint themes

 
Getting ready to give a presentation and noticed that all 14 modules are using the wrong theme.  Started in changing the theme on the seeming endless list of files and I thought, how about powershell.  Well after a quick search found this great article from Ed Wilson, thank you again ED!  http://blogs.technet.com/b/heyscriptingguy/archive/2010/05/11/hey-scripting-guy-may-11-2010.aspx
I did simplify his code by just using one folder that contains both the theme an PowerPoint slides. Just change $themepath  to the name and location or your theme and $path to the folder location of your powerpoint slides are you are set.
Add-type -AssemblyName office
$Application = New-Object -ComObject powerpoint.application
$application.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
$themePath = "c:\presentations\moc.thmx"
$path = "C:\Presentations"
Get-ChildItem -Path $path -Include "*.ppt", "*.pptx" -Recurse |
ForEach-Object {
 $presentation = $application.Presentations.open($_.fullname)
 $presentation.ApplyTemplate($themePath)
 $presentation.Save()
 $presentation.Close()
 "Modifying $_.FullName"
} 

$application.quit()
$application = $null
[gc]::collect()
[gc]::WaitForPendingFinalizers()