PoshCode Logo PowerShell Code Repository

Update SharePoint Search scopes, useful when revving the Scope definitions.

  1. function Update-Scopes($siteUrl)
  2. {
  3.         [void][reflection.assembly]::Loadwithpartialname("Microsoft.SharePoint") | out-null
  4.         [void][reflection.assembly]::Loadwithpartialname("Microsoft.office.server.search") | out-null
  5.        
  6.         $s = [microsoft.sharepoint.spsite]$siteUrl
  7.         $sc = [microsoft.office.server.servercontext]::GetContext($s)
  8.         $search = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($sc)
  9.         $scopes = [microsoft.office.server.search.administration.scopes]$search
  10.         $scopes.StartCompilation()
  11.         while ($scopes.CompilationPercentComplete -lt 100) { sleep -seconds 3; write-host "$($scopes.CompilationPercentComplete)% complete" }
  12. }
  13.  
  14. #usage: paste this text into your PowerShell window, then call the "Update-Scopes" function as noted below
  15. Update-Scopes -siteUrl "http://dev/sites/MySPSite/"

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me