Install and configure iFilters for SharePoint 2010 using PowerShell & updated PS SP2010 Utils

by ravikanthchaganti on June 1, 2010
543 Views

This is one of the recent additions to my SharePoint 2010 PowerShell scripts & Utilities project on Codeplex. I wrote a generic script cmdlet to take care of iFilter MSI install, make changes to DOCICON.XML, and add the crawl extension to the search service application.

This could be useful to those who perform frequent SharePoint 2010 farm configuration. You can copy just this script @ http://pssp2010utils.codeplex.com/SourceControl/changeset/view/14b6c2e1b6ec#SPInstallUtils.psm1

This script requires to be run at the SharePoint 2010 management shell since there is a dependency on New-SPEnterpriseSearchCrawlExtension cmdlet.

IFilter Install

IFilter Install

Whatever iFilters I’d Installed so far were all MSI with silent install support. So, making this a generic script cmdlet was a choice for me.

function Install-SPIFilter {
   [CmdletBinding()]
   param (
       [Parameter(Mandatory=$true)]
       [ValidateScript({ if ((Get-Item $_).Extension -eq ".msi") {$true}})]
       [String]$IFilterMSI,            

       [Parameter(Mandatory=$true)]
          [String]$filetype,            

       [Parameter(Mandatory=$false)]
          [String]$Icon,            

       [Parameter(Mandatory=$true)]
          [String]$SearchServiceApplicationId
   )            

   $script:TEMPLATE = $("$env:CommonProgramFiles\Microsoft Shared\Web Server Extensions\14\TEMPLATE")            

   #Install MSI
   Write-Host
   Write-Host -NoNewline "Installing $IFilterMSI"            

   try {
       $msiProcess = [System.Diagnostics.process]::Start("msiexec","/i $IFilterMSI /quiet /qn")
       $msiProcess.WaitForExit()
       if ($msiProcess.ExitCode -ne 0) {
           Write-Host -ForegroundColor Red "`t [Error]"
           Return $false
       } else {
           Write-Host -ForegroundColor Green "`t [Done]"
       }            

   }            

   catch {
       Write-Error "`nThere was an error starting the install process"
   }            

   #Add docicon if $icon exists
   if ($icon) {
       Write-Host
       Write-Host -NoNewline "Adding $icon to DOCICON.XML"
       $iconName = (Get-Item $icon).Name            

       #Copy the icon file to 14 hive
       Copy-Item -Path $icon -Destination $("$Script:TEMPLATE\IMAGES") -Force
       #Create a copy of DOCICON.XML
       Copy-Item -Path "$script:TEMPLATE\XML\DOCICON.XML" -Destination "$script:TEMPLATE\XML\DOCICON.BAK" -Force            

       #Read XML
       try {
           $xml = New-Object XML
           $xml.Load("$script:TEMPLATE\XML\DOCICON.XML")
           $cloneNode = @($xml.DocIcons.ByExtension.Mapping)[0]
           $newNode = $cloneNode.Clone()
           $newNode.Key = $fileType
           $newNode.Value = $iconName
           $newNode.EditText = $fileType
           $newNode.OpenControl = ""
           $xml.DocIcons.ByExtension.AppendChild($newNode) | Out-Null
           $xml.Save("$script:TEMPLATE\XML\DOCICON.XML")
       }
       catch {
           Write-Error "`nError occurred while loading/manipulating XML"
           return $false
       }
       Write-Host -ForegroundColor Green "`t [Done]"
   }            

   #Add crawl extension
   Write-Host
   Write-Host -NoNewline "Adding crawl extension"
   try {
       New-SPEnterpriseSearchCrawlExtension -Name $fileType -SearchApplication $SearchServiceApplicationId | Out-Null
   }
   catch {
       Write-Error "`nError occured while adding crawl extension"
       return $false
   }
   Write-Host -ForegroundColor Green "`t [Done]"
   return $true
}

You can find the complete documentation of PSSP2010Utils @ http://pssp2010utils.codeplex.com/documentation

Related Posts

{ 1 trackback }

Leave a Comment

Previous post:

Next post: