Friday, August 07, 2015

Find below the PowerShell script to save PDF version of Word documents in a SharePoint 2013 document library. Take note of the input parameters and corresponding value in the script below, so that you can set your own value for this script to run properly

# Uncomment the line below if running this script within Windows PowerShell ISE#Add-PSSnapin Microsoft.SharePoint.PowerShell

# Replace the variable "SubFolderName" with your own folder name or remove SubFolders[..] if querying all files in root folderforeach ($itm in $list.RootFolder.SubFolders["SubFolderName"].Files){
# Replace .docx with .doc or other Word file extensions depending on the Word formats you are trying to convert if($itm.Name.ToLower().EndsWith(".docx") -eq $true) { Write-Host $($itm.ServerRelativeUrl) # Note the job below will convert all Word files to PDF and save it into the same location as where source Word document are. Modify code below to save to alternate location $conversionJob.AddFile($($web.Site.MakeFullUrl($itm.ServerRelativeUrl)), $($web.Site.MakeFullUrl($itm.ServerRelativeUrl).ToLower().Replace(".docx", ".pdf")))