Getting Windows SharePoint Services and Microsoft Search Server 2008 Express to index PowerShell script (.PS1) files

A guest blog apperance by Nigel Boulton

As a scripter of more years than I care to think about, I’ve lost count of the number of times that either somebody has asked me how to do something specific in a particular scripting language, or I need to remember for a new script that I’m writing.

In most cases, I know I’ve done it before, but I never seem to be able to remember in which script I did it! For this reason, I thought it would be useful to build a fully searchable script repository that I could access from wherever I happened to be at the time.

I did this using Windows SharePoint Services 3.0 and Microsoft Search Server 2008 Express. I’m not going to go into details here of how to do this, as it’s fairly straightforward stuff – basically a standard install of these products, with separate document libraries to hold the scripts and programs I’ve written in the past in various languages.

The document libraries are held in a SharePoint site and indexed by Search Server. Instead, this post is about the part that I struggled with – and didn’t manage to find a working solution for online – namely how to get Search Server to correctly index PowerShell script files.

My crawl logs were reporting the following warning for every .ps1 file I’d uploaded to the document library: ‘Crawled (The filtering process could not process this item. This might be because you do not have the latest file filter for this type of item. Install the corresponding filter and retry your crawl.)’, and naturally, no search results were being returned for text in .ps1 files.

I struggled to find a way round this for a while, until Alan and Hal kindly put my dilemma out to the community. Oisin experimented and determined how to do it on his MOSS 2007 system, and although his settings didn’t work directly on my system (most likely because of the differences between the products), they set me on the right track to working out some that did (thanks again Oisin). So this blog post is in the hope that someone else in the community might benefit from this experience. Here are the necessary steps:

  1. In Search Server Admin, go to File types – New File Type and add “ps1” (no leading dot)
  2. In Regedit, create a new key called “.ps1” under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\12.0\Search\Setup\ContentIndexCommon\Filters\Extension and set it’s (Default) value to {4A3DD7AB-0A6B-43B0-8A90-0D8B0CC36AAB} (the GUID is the same as the one for the .txt extension in same parent key)
  3. Run net stop osearch
  4. Run net start osearch
  5. Start a full crawl on the Content Source
  6. Check the Crawl log

The above procedure can be applied for other file types that Search Server doesn’t index by default (and are essentially plain text files that the text filter can understand), although bear in mind that certain file types are blocked by default and it will be necessary to go into Central Admin – Operations (under Security Configuration) – Blocked file types, and then remove the desired file type from the list.

Once this was working, I thought it would be nice to add the finishing touch by giving my PowerShell scripts the proper icon within SharePoint, instead of the boring default blank white document. A bit of online research turned up a procedure for adding indexing of .pdf files, which I adapted to provide an icon for .ps1 files (this is based on http://support.microsoft.com/kb/837849). To do this:

  1. Download and save a 17×17 PowerShell script icon gif file (I didn’t have one to hand but Google Image Search did the trick nicely), and save it as:
    C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Images\icps1.gif
  2. Edit the “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Xml\DocIcon.xml” file and insert the following line in the <ByExtension> section, in the appropriate place alphabetically for PS1.

    <Mapping Key=”ps1″ Value=”icps1.gif” OpenControl=””/>

  3. Run iisreset /noforce

One final tip – the versioning feature of SharePoint is very useful for maintaining a history of changes made to scripts, but only the current version (and it’s version notes) are indexed, so if I find myself needing to remove any code that I would still like to be able to search for in future, I tend to save the existing script out, then upload it with a different (but descriptive) file name, before replacing the version stored in SharePoint with the modified script.

2 thoughts on “Getting Windows SharePoint Services and Microsoft Search Server 2008 Express to index PowerShell script (.PS1) files

  1. Virtu-Al

    Thanks for the Guest post Nigel, having seen this work its amazing, an easy way to search your scripts and a nice interface. Well done and Thanks Nigel.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.