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!

This entry was posted in SharePoint and tagged , , . Bookmark the permalink.
0 0 votes
Article Rating
Subscribe
Notify of
guest

Solve the maths problem shown below before posting: *

0 Comments
Inline Feedbacks
View all comments