{"id":1615,"date":"2014-01-21T16:12:59","date_gmt":"2014-01-21T16:12:59","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1615"},"modified":"2014-01-21T16:12:59","modified_gmt":"2014-01-21T16:12:59","slug":"get-searchserviceapplication-powershell","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2014\/01\/21\/get-searchserviceapplication-powershell\/","title":{"rendered":"Get SearchServiceApplication in PowerShell"},"content":{"rendered":"<p>In C# when retrieving the default <a href=\"http:\/\/msdn.microsoft.com\/library\/ee573121(v=office.14)\" title=\"SearchServiceApplication Class\" target=\"_blank\">SearchServiceApplication<\/a> object you might do something like the following, if you were trying to initiate a new <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.office.server.search.administration.schema.ASPX\" title=\"Schema class\" target=\"_blank\">Schema<\/a> object, for example:<\/p>\n<pre lang=\"csharp\">\r\nSPServiceContext serviceContext = SPServiceContext.GetContext(SPContext.Current.Site);\r\n\r\nSearchServiceApplicationProxy searchApplicationProxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;\r\n\r\nGuid applicationId = searchApplicationProxy.GetSearchServiceApplicationInfo().SearchServiceApplicationId;\r\n\r\nSearchServiceApplication searchApplication = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(applicationId);\r\n\r\nSchema schema = new Schema(searchApplication);\r\n<\/pre>\n<p>If you&#8217;re looking to implement something similar in PowerShell, you don&#8217;t have to write quite as much code.  Take a look at the following script, which achieves the same goal:<\/p>\n<pre lang=\"powershell\">\r\n[System.Reflection.Assembly]::LoadWithPartialName(\"Microsoft.SharePoint\");\r\n\r\n$searchApplication = Get-SPEnterpriseSearchServiceApplication \"Search Service Application\"\r\n\r\n$schema = New-Object Microsoft.Office.Server.Search.Administration.Schema($searchApplication);\r\n<\/pre>\n<p>The call to <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ff608050.aspx\" title=\"Get-SPEnterpriseSearchServiceApplication\" target=\"_blank\">Get-SPEnterpriseSearchServiceApplication<\/a> is all that&#8217;s required to retrieve the default SearchServiceApplication object.<\/p>\n<p>Simples!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 = &hellip; <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2014\/01\/21\/get-searchserviceapplication-powershell\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[3],"tags":[41,20,81],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-q3","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1615"}],"collection":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1615"}],"version-history":[{"count":7,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1615\/revisions"}],"predecessor-version":[{"id":1631,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1615\/revisions\/1631"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1615"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}