Patrick's SharePoint Blog

SharePoint's Booming world

Using Powershell to change registry keys for search crawler

Posted by Patrick Boom on May 17, 2010

In one of my earlier posts, I described a way to use PowerShell to change settings in a SharePoint 2007 farm.  That started out as my first PowerShell script and I have witnessed the power behind it all.

In our project, we needed a server wide adjustment of the registry for the SharePoint index servers across all farms. Of course, multiple ways to do this, but here is where PowerShell shows its power. I needed to change two registry settings, both covering the maximum file size that is crawled by the indexer. By default, this is 16 MB (mutiplied by 4), leaving a total of 64 MB indexed in each file. As we now enlarged trhe maximum upload size to 100 MB, we needed the crawl settings to be adjusted. To be honest, I was quite surprised it would only take me two lines of script to make this work. The registry keys in question were those below:

HKLM\SYSTEM\CURRENTCONTROLSET\
HKLM\SOFTWARE\MICROSOFT\OFFICE SERVER\12.0\SEARCH\GLOBAL\GATHERING MANAGER

And to change these, the following lines of script would suffice. I have also added some additional lines to check whether we actually are at the index server, otherwise, these changes would have no effect. Pay special attention to the way the registry is accessed. In principle, it is accessed as a file path.

Set Search Crawler Settings

Write-Host “Set registry values for search”
Write-Host “=======================================================================”
Write-Host “”

if ( (Get-Itemproperty  -Path “hklm:\SOFTWARE\Microsoft\Office Server\12.0\Search\Global”).Index -eq 1 ) {
    Write-Host -f green “Validated that this server is the index Server ” 
} else  {
    throw “This server is the not the SharePoint index Server ” 
}

Write-Host “Processing MaxTextFilterBytes”
set-itemproperty “hklm:\system\currentcontrolset\control\contentindex” MaxTextFilterBytes -type “DWord” -value “104857600” -force

Write-Host -f green “Done…”
Write-Host “Processing MaxDownloadSize”
set-itemproperty “hklm:\software\microsoft\office server\12.0\search\global\gathering manager” MaxDownloadSize -type “DWord” -value “26214400” -force

Write-Host -f green “Done…”
Write-Host -f green “Script completed”
Write-Host “=======================================================================”
Write-Host “”

In addition to these registry changes, a couple of more settings need to be set to get the entire maximum upload size working. Above registry changes instruct the search crawler to enlarge the crawled file size. But this still does not allow SharePoint to upload larger files.  Besides SharePoint changes, OS level changes also need to be make on the client side to allow the WebDAV protocol to upload larger files. These are however out of scope of this blog post. In short, three steps are needed to support larger files on SharePoint:

1. Change the crawler settings to support larger files in the registry.
2. Change the Maximum File Size for the Web Application.
3. Change the connection time out setting on the SharePoint search service. (OSearch)

To change the crawler settings, the PowerShell script is located above. To execute steps 2 and 3 in above list, the following PowerShell scripts do the job:

Set Maximum File Size for Web Application

[Void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
if ($farm -eq $null ) {
    throw “Could not connect to the SharePoint farm”
}

Write-Host “”
Write-Host “====================================================================”
Write-Host “”
$websvcs = new-object  Microsoft.SharePoint.Administration.SPWebServiceCollection($farm)
if ($websvcs.Length -eq 0 ) {
    throw “Could not connect to any SharePoint Web Service in the farm”
}
$FileSize = 100
$MaximumFileSize = 0

foreach ($websvc in $websvcs) {
    foreach ($webapp in $websvc.WebApplications) {
 if (($webapp.MaximumFileSize -ne $FileSize) -and ($webapp.MaximumFileSize -lt $FileSize))
     {
  Write-Host “Set file size for web application $webapp.Name”
  $webapp.MaximumFileSize = $FileSize
  $MaximumFileSize = $webapp.MaximumFileSize
  $webapp.Update()
  Write-Host -f green “New file size $MaximumFileSize MB”
 } else {
         Write-Host -f green “Maximum file size for $($webapp.Name) was already set to or larger than $FileSize MB”
 }
    }
}
Write-Host -f green “Script completed”
Write-Host “====================================================================”

Set Connection TimeOut for Search Crawler

[Void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
if ($farm -eq $null ) {
    throw “Could not connect to the SharePoint farm”
}

Write-Host “====================================================================”
Write-Host “”

$searchsvcs = @($farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.Office.Server.Search.Administration.SearchService]})
if ($searchsvcs.Length -eq 0 ) {
    throw “Could not connect to any SharePoint Search Service in the farm”
}

$TimeOut = 90
foreach ($searchsvc in $searchsvcs) {
    if (($searchsvc.ConnectionTimeOut -ne $Timeout) -or ($searchsvc.AcknowledgementTimeout -ne $Timeout))
    {
        Write-Host “Set connection and acknoledgement timeouts for $($searchsvc.Name) to $Timeout”
        $searchsvc.ConnectionTimeOut = $Timeout;
        $searchsvc.AcknowledgementTimeout = $Timeout;
        $searchsvc.Update()
 Write-Host -f green “Done…”

    } else {
        Write-Host -f green “Connection timeout for $($searchsvc.Name) was already set to $Timeout”
    }
}

Write-Host -f green “Script completed”
Write-Host “====================================================================”

Thats it! Using three simple scripts, we can change the settings in our entire farm to use new file upload settings and have it supported by the sarch crawler.

CU!

Advertisements

5 Responses to “Using Powershell to change registry keys for search crawler”

  1. Kevin said

    Hi, first excuse me for my bad english i am french 😀

    I want to thank you for this tips but i have one problem, i will appreciate if you can help me to resolve this..

    The problem is: i have a key registry (PEACY) that contain subkeys (0, 1 , 101, 100…..) like this for example:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PEACY]

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PEACY]
    “Name”=”Adobe Reader (0)”
    “Status”=”success”
    “Prev_Timestamp”=”2012/09/05 05:05:10”
    “Prev_UpdateVer”=”63”
    “Prev_SubfunctionPkey”=”{68DE7BC5-CCE7-40A9-A222-AB5B98A57895}”
    “LastInstallDate”=”2013-08-21 09:30:30”

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PEACY\1006]
    “Name”=”Microsoft Hotfix Rollout Status (1006)”
    “Status”=”success”
    “UpdateVer”=”3”

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PEACY\1008]
    “Name”=”PEACY Performance Monitor (1015)”
    “Status”=”unavailable”
    “install_never”=”1”

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PEACY\1009]
    “Name”=”PEACY Performance Monitor (1009)”
    “status”=”unavailable”
    “install_never”=”1”
    “hidden”=dword:00000001
    .
    .
    .
    .
    .

    ————————————————

    I want to retrieve on every subkeys keys from (SOFTWARE\Wow6432Node\PEACY\) the content of the “Name” keys, but only if the other keys “Status” contain the value “Success” like my example..and finally store the result on text file to get a list of software name :
    ————————–
    Adobe Reader (0)
    Microsoft Hotfix Rollout Status (1006)

    ————-

    i need you’r help because i am beginner on powershell, thanks for advance 🙂

    Best Regards
    Kevin

  2. Finding Sydney serviced apartments online is really easy and quick.
    The serviced apartments are generally positioned in those areas that
    are nearby to the transport facilities. Apart from the above described benefits, short stay apartments in Sydney
    provide several other facilities to every guest.
    Although luxury hotels in Melbourne are a popular accommodation option in such cases, but
    nowadays the concept of short stay apartment and serviced apartments are being popular and perfect alternative of luxury hotel.

  3. When someone writes an piece of writing he/she keeps the
    image of a user in his/her brain that how a user can understand it.

    Thus that’s why this piece of writing is outstdanding. Thanks!

  4. Hi there friends, pleasant article and nice arguments commented here,
    I am genuinely enjoying by these.

  5. Hello There. I discovered your blog using msn. That is
    a really smartly written article. I will make sure to bookmark
    it and come back to read more of your useful information. Thank you for the post.
    I’ll certainly return.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: