Tag Archive for Search

Get SearchServiceApplication in PowerShell

In C# when retrieving the default SearchServiceApplication object you might do something like the following, if you were trying to initiate a new Schema object, for example:

SPServiceContext serviceContext = SPServiceContext.GetContext(SPContext.Current.Site);
 
SearchServiceApplicationProxy searchApplicationProxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;
 
Guid applicationId = searchApplicationProxy.GetSearchServiceApplicationInfo().SearchServiceApplicationId;
 
SearchServiceApplication searchApplication = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(applicationId);
 
Schema schema = new Schema(searchApplication);

If you’re looking to implement something similar in PowerShell, you don’t have to write quite as much code. Take a look at the following script, which achieves the same goal:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
 
$searchApplication = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
 
$schema = New-Object Microsoft.Office.Server.Search.Administration.Schema($searchApplication);

The call to Get-SPEnterpriseSearchServiceApplication is all that’s required to retrieve the default SearchServiceApplication object.

Simples!

Get SearchServiceApplication object instance

Looking to retrieve the SearchServiceApplication object for the current site? It’s pretty straight forward, as the following demonstrates:

Start by adding the following namespace to your class

using Microsoft.Office.Server.Search.Administration;

The Microsoft.Office.Server assembly can be found in the ISAPI folder of the SharePoint hive.
Read more

Follow

Get every new post delivered to your Inbox

Join other followers: