SharePoint Use Cases

  • Home
  • About
  • Our Tools
  • Contact me
SharePoint, SharePoint 2010

Automate PDF configuration for SharePoint 2010 via PowerShell

Toni Frankola - February 15, 2011

Configuring PDF related stuff for SharePoint 2010 (and 2007) is very simple, yet annoying and often forgotten SharePoint configuration step. There are nice articles (link, link) to help you configure it but when you do it manually chances are you will misconfigure something.

I wrote a simple PowerShell script to automate this, and it will do everything for you > configure PDF Icon and PDF crawling.

Here is what you need to do:

  • Download and install the Adobe PDF iFilter
  • Configure SharePoint Foundation search service via Central Admin (or PowerShell)
  • Download the Adobe PDF icon (select Small 24 x 24, but resize it to 17 x 17) and save it to a folder on your SharePoint server as pdficon_small.gif
  • Download the script below and place it to the same folder as Adobe PDF Icon
  • Run the script as administrator from Powershell shell

Special thanks to Agnes Molnar for testing this script. If you want to learn more about PowerShell and SharePoint 2010 check SharePoint 2010 Unleashed.

Update May 4th 2011. – Agnes Molnar – added Adobe to PATH variable

cls
function Get-FileFormatDate {
param( [DateTime]$Date = [DateTime]::now )
return $Date.ToUniversalTime().toString( “yyyy-MM-dd_hh-mm-ss” )
}
if((Get-PSSnapin | Where {$_.Name -eq “Microsoft.SharePoint.PowerShell”}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$continue = Read-Host “This script will change SharePoint configuration files, registry and will restart your IIS! Would you like to continue (Y/N)”
if($continue -eq “Y”)
{
Write-Host -ForegroundColor Yellow “Configuring PDF Icon…”
$SharePointRoot = “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14”;
$DocIconFolderPath = “$SharePointRoot\TEMPLATE\XML”;
$DocIconFilePath = “$DocIconFolderPath\docicon.xml”;
Write-Host “Creating backup of DocIcon.xml file…”
$dateNow = Get-FileFormatDate
$backupFile = “$DocIconFolderPath\Backup_DocIcon_” + $dateNow + “.xml”
Copy-Item $DocIconFilePath $backupFile
$pdfIcon = “pdficon_small.gif”;
while((Get-Item $pdfIcon) -eq $null)
{
Read-Host “$pdfIcon is missing. Download it from http://www.adobe.com/misc/linking.html and place it to this folder. Press any key to continue…”;
}
Copy-Item $pdfIcon “$SharePointRoot\Template\Images”;
$pdfNode = select-xml -path $DocIconFilePath -xpath “/DocIcons/ByExtension/Mapping[@Key=’pdf’]” | select-object -expandProperty Node
if($pdfNode -eq $null)
{
$xml= \ (Get-Content $DocIconFilePath)
$a = $xml.selectSingleNode(“/DocIcons/ByExtension”)
$addnode = $xml.createElement(“Mapping”)
$a.AppendChild($addNode)
$keyAttribute = $xml.CreateAttribute(“Key”)
$keyAttribute.set_Value(“pdf”)
$addNode.SetAttributeNode($keyAttribute)
$valueAttribute = $xml.CreateAttribute(“Value”)
$valueAttribute.set_Value(“pdficon_small.gif”)
$addNode.SetAttributeNode($valueAttribute)
$xml.Save($DocIconFilePath)
}
Write-Host -ForegroundColor Yellow “Configuring search crawl extension…”
$searchServiceApp = Read-Host “Type the name of your search service application (e.g. Search Service Application)”
$searchApplicationName = Get-SPEnterpriseSearchServiceApplication $searchServiceApp
if($searchApplicationName -ne $null)
{
if(($searchApplicationName | Get-SPEnterpriseSearchCrawlExtension “pdf”) -eq $null)
{
$searchApplicationName | New-SPEnterpriseSearchCrawlExtension “pdf”
}
}
Write-Host -ForegroundColor Yellow “Updating registry…”
if((Get-Item -Path Registry::”HKLM\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\Filters\.pdf”) -eq $null)
{
$item = New-Item -Path Registry::”HKLM\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\Filters\.pdf”
$item | New-ItemProperty -Name Extension -PropertyType String -Value “pdf”
$item | New-ItemProperty -Name FileTypeBucket -PropertyType DWord -Value 1
$item | New-ItemProperty -Name MimeTypes -PropertyType String -Value “application/pdf”
}
if((Get-Item -Path Registry::”HKLM\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf”) -eq $null)
{
$registryItem = New-Item -Path Registry::”HKLM\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf”;
$registryItem | New-ItemProperty -Name “(default)” -PropertyType String -Value “{E8978DA6-047F-4E3D-9C78-CDBE46041603}”
}
[System.Environment]::SetEnvironmentVariable(“PATH”, $Env:Path + “;C:\Program Files\Adobe\Adobe PDF iFilter 9 for 64-bit platforms\bin”, “Machine”)

Write-Host -ForegroundColor Yellow “Restarting SharePoint Foundation Search Service…”
Restart-Service SPSearch4
Write-Host -ForegroundColor Yellow “Restarting SharePoint Search Service…”
Restart-Service OSearch14
Write-Host -ForegroundColor Yellow “Restarting IIS…”
iisreset
Write-Host -ForegroundColor Green “Installation completed…”
}

Tags | automation, pdf, powershell
 0
Share Now

Toni Frankola

Entrepreneur, IT consultant, speaker, blogger, and geek. Co-founder of syskit.com.

You Might Also Like

SharePoint, SharePoint 2010

Remove all Service Applications from SharePoint 2010 farm with PowerShell

May 31, 2010
SharePoint, SharePoint 2010

Retract SharePoint solution from Central Admin with PowerShell

July 7, 2010
SharePoint, SharePoint 2010

Add all site collections as PerformancePoint trusted locations via PowerShell

August 4, 2010
SharePoint, SharePoint 2010

Run all SharePoint 2010 health rules now!

October 18, 2010
Previous Post Could not save changes. The Content type is in use.
Next Post SharePoint Search error: The service cannot be started, either because it is disabled or because it has no enabled devices associated with it

Archives

  • December 2021 (1)
  • June 2021 (1)
  • January 2021 (1)
  • July 2019 (1)
  • June 2019 (2)
  • March 2019 (1)
  • February 2019 (3)
  • October 2018 (2)
  • August 2018 (2)
  • June 2018 (1)
  • April 2018 (1)
  • February 2018 (1)
  • January 2018 (1)
  • June 2017 (1)
  • April 2017 (1)
  • February 2017 (1)
  • November 2016 (2)
  • August 2016 (1)
  • July 2016 (2)
  • March 2016 (1)
  • February 2016 (2)
  • January 2016 (1)
  • November 2015 (2)
  • December 2014 (1)
  • November 2014 (2)
  • July 2014 (2)
  • June 2014 (2)
  • May 2014 (1)
  • April 2014 (2)
  • March 2014 (1)
  • February 2014 (4)
  • January 2014 (2)
  • December 2013 (1)
  • September 2013 (1)
  • July 2013 (1)
  • June 2013 (1)
  • May 2013 (1)
  • April 2013 (3)
  • February 2013 (1)
  • December 2012 (1)
  • November 2012 (1)
  • September 2012 (1)
  • August 2012 (1)
  • July 2012 (2)
  • June 2012 (4)
  • April 2012 (1)
  • February 2012 (1)
  • January 2012 (1)
  • November 2011 (2)
  • October 2011 (2)
  • September 2011 (2)
  • July 2011 (3)
  • May 2011 (2)
  • April 2011 (1)
  • March 2011 (4)
  • February 2011 (3)
  • January 2011 (4)
  • December 2010 (4)
  • November 2010 (3)
  • October 2010 (3)
  • September 2010 (4)
  • August 2010 (1)
  • July 2010 (4)
  • May 2010 (2)
  • April 2010 (2)
  • March 2010 (3)
  • January 2010 (2)
  • December 2009 (3)
  • November 2009 (5)
  • October 2009 (2)
  • August 2009 (7)
  • July 2009 (3)
  • June 2009 (4)
  • May 2009 (3)
  • April 2009 (5)
  • March 2009 (8)
  • February 2009 (5)
  • January 2009 (8)
  • December 2008 (9)
  • November 2008 (8)
  • October 2008 (7)
  • September 2008 (4)
  • August 2008 (6)
  • July 2008 (5)
  • June 2008 (3)
  • May 2008 (4)
  • April 2008 (6)
  • March 2008 (4)
  • February 2008 (3)
  • January 2008 (6)
  • December 2007 (1)
  • November 2007 (3)
  • October 2007 (3)
  • September 2007 (2)
  • August 2007 (1)
  • July 2007 (12)
  • June 2007 (2)
  • May 2007 (3)

Connect Us

All postings on this blog are provided “AS IS” with no warranties, and confer no rights. All entries in this blog are my opinion and don’t necessarily reflect the opinion of my employer.

  • Home
  • About
  • Our Tools
  • Contact me

Copyright (c) Toni Frankola 2008. - 2019.