My career in technology

As I mentioned in an earlier post, I’ve been working a lot with PowwerShell recently.

Since I am just learning my way around, I have been doing a lot of really cool but really derivative scripts, or the scripts have been too requirements-specific to be of much general use and, in my opinion, to be worth posting.

But we had a requirement to upgrade Office 2007 files to the Office 2010 formats that there wasn’t a specific template that I could find with Google.

There were good scripts for converting .doc to .docx with PowerShell.

There were good scripts for converting .xls to .xlsx with PowerShell (though there was a gotcha I found out about too!).

To do the conversion from .ppt to .pptx, though, there were no direct examples to follow.

I used the .xls to .xlsx script as a starting point, and dug through the object model documentation for Microsoft.Office.Interop.PowerPoint and hacked a bit until I got it.

For your reference, here is the result.

$PpFixedFormat = [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsOpenXMLPresentation
write-host $PpFixedFormat
$PowerPoint = New-Object -ComObject PowerPoint.application
$folderpath = "c:\fso"
$filetype ="*ppt"
Get-ChildItem -Path $folderpath -Include $filetype -recurse |
ForEach-Object `
	$path = ($_.fullname).substring(0, ($_.FullName).lastindexOf("."))

	"Converting $path"
	$Presentation = $$_.fullname)

	$path += ".pptx"
	$Presentation.saveas($path, $PpFixedFormat)

	$oldFolder = $path.substring(0, $path.lastIndexOf("\")) + "\old"

	write-host $oldFolder
	if(-not (test-path $oldFolder))
		new-item $oldFolder -type directory

	move-item $_.fullname $oldFolder

$PowerPoint = $null

A big thanks to Gabriel Cebrian, Ed Wilson and Craig Liebendorfer for leading the way!

More Technology posts.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: