Script for creating SharePoint 2013 Search service application

by Robi 23. September 2015 12:07
Since a lot of people are asking me what is the best way to create seach service application in SharePoint 2013, I decided to share the script I use to create one.   The folowing script is used for the following Search Infrastructure: Server name Type Components WFE 1 Web front end Admin component Query processing component Index component WFE 2 Web front end Admin component Query processing component Index component Index server Application server Crawl component Content processing Admin component Analytics component   You can of course modify the script as needed. Add-PSSnapin Microsoft.SharePoint.PowerShell --EA 0   ## Change these per your environment ## $databaseServerName="dbserver"   ################ search servers in farm ################ $wfe1 = "wfe-1" $wfe2 = "wfe-2" $searchServerName = "index-1" ##########################################################     ################ Search information ################   $saAppPoolName = "Search_AppPool" $appPoolUserName = "" #Enter search service app pool $IndexLocation = "" #Enter location for search Index e.g. I:\Search $usagaDatabaseName="SP2013_SA_Usage" #Modify database name as needed $searchDatabaseName="SP2013_SA_Search" #Modify database name as needed $contactEmail="" #Enter Search contact email $defaultContenAccessAccount="" #Enter content access account $defaultContenAccessAccountPassword=ConvertTo-SecureString -AsPlainText -Force '' #Enter content access account password $windowsService=Get-SPManagedAccount "" #Enter managed account for search services account $windowsServicePassword=ConvertTo-SecureString -AsPlainText -Force '' #Enter password for search services account   ## Service Application Names ## ## Included Usage and Health, as it does get provisioned and if you want to define DB name ## ## Also Usage Proxy Status is stopped which cause Search Application Topology to not find Admin Service ## $searchSAName = "Search_SA" #Modify Search service application name $usageSAName = "UsageHealth_SA" #Modify Usage service application name   ##########################################################     #region Create folders   #Ustvarimo mapo za search index if(!(test-path $IndexLocation)){ New-Item -Path $IndexLocation -ItemType directory } else{ Remove-Item $IndexLocation -Recurse New-Item -Path $IndexLocation -ItemType directory }   #endregion     #region Application pool #Application pool objekt $saAppPool = Get-SPServiceApplicationPool -Identity $saAppPoolName -EA 0 if($saAppPool -eq $null) { Write-Host "Creating Service Application Pool..."   $appPoolAccount = Get-SPManagedAccount -Identity $appPoolUserName -EA 0 if($appPoolAccount -eq $null) { Write-Host "Please supply the password for the Service Account..." $appPoolCred = Get-Credential $appPoolUserName $appPoolAccount = New-SPManagedAccount -Credential $appPoolCred -EA 0 }   $appPoolAccount = Get-SPManagedAccount -Identity $appPoolUserName -EA 0   if($appPoolAccount -eq $null) { Write-Host "Cannot create or find the managed account $appPoolUserName, please ensure the account exists." Exit -1 }   New-SPServiceApplicationPool -Name $saAppPoolName -Account $appPoolAccount -EA 0 > $null      }   #endregion   # region Usage service application Write-Host "Creating Usage Service and Proxy..."   $serviceInstance = Get-SPUsageService   New-SPUsageApplication -Name $usageSAName -DatabaseServer $databaseServerName -DatabaseName $usagaDatabaseName -UsageService $serviceInstance > $null   $usa = Get-SPServiceApplicationProxy | where {$_.TypeName -like "Usage*"} $usa.Provision()   #endregion     #region Start services Create search service application   Write-Host "Creating Search Service and Proxy..."   Write-Host " Starting Services..."   Write-Host "Starting service on wfe1" -ForegroundColor Yellow Start-SPEnterpriseSearchServiceInstance $wfe1 Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $wfe1   Write-Host "Service on wfe1 started" -ForegroundColor green   Write-Host "Starting service on wfe2" -ForegroundColor Yellow Start-SPEnterpriseSearchServiceInstance $wfe2 Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $wfe2 Write-Host "Service on wfe2 started" -ForegroundColor green   Write-Host "Starting service on index server" -ForegroundColor Yellow Start-SPEnterpriseSearchServiceInstance $searchServerName Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $searchServerName Write-Host "Service on index started" -ForegroundColor green   Write-Host " Creating Search Application..." $searchApp = New-SPEnterpriseSearchServiceApplication -Name $searchSAName -ApplicationPool $saAppPoolName -DatabaseServer $databaseServerName -DatabaseName $searchDatabaseName Write-Host "Search Service Application Created"   #endregion   #region Get Initial topology and create clone   $searchInstancewfe1 = Get-SPEnterpriseSearchServiceInstance $wfe1 $searchInstancewfe2 = Get-SPEnterpriseSearchServiceInstance $wfe2 $searchInstanceIndex = Get-SPEnterpriseSearchServiceInstance $searchServerName   write-host "Getting initial topology" $InitialSearchTopology = $searchApp | Get-SPEnterpriseSearchTopology -Active   $ssa = Get-SPEnterpriseSearchServiceApplication   #gets the active search topology from search service application $ssa.ActiveTopology   Write-Host $ssa.ActiveTopology   #To clone the active topology   $clone = $ssa.ActiveTopology.Clone()   #endregion     #region Modify default topology and activate   ############################### Index Server ##################################################################### Write-Host "Starting to configure indexing server" -ForegroundColor Yellow write-host "Creating Admin Component" -ForegroundColor Yellow New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $searchInstanceIndex write-host -ForegroundColor Green "Admin Component Created"   write-host "Creating Content Processing component" -ForegroundColor Yellow New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchInstanceIndex write-host -ForegroundColor Green "Content Processing component Created"   write-host "Creating Analyticis Processing Component" -ForegroundColor Yellow New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchInstanceIndex write-host -ForegroundColor Green "Analyticis Processing Component Created"   write-host "Creating Crawl Component" -ForegroundColor Yellow New-SPEnterpriseSearchCrawlComponent –SearchTopology $clone -SearchServiceInstance $searchInstanceIndex write-host -ForegroundColor Green "Crawl Component Created" Write-Host "Index server configured ###################################################################" -ForegroundColor Green   #=============================== Index Server ===================================================================       ############################### WFE1 ############################################################################   Write-Host "Configuring WFE1" -ForegroundColor Yellow New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $searchInstancewfe1 write-host -ForegroundColor Green "Admin Component Created on WFE1" write-host "Creating Index on WFE1 Component" -ForegroundColor Yellow New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $searchInstancewfe1 -RootDirectory $IndexLocation write-host -ForegroundColor Green "Index Component on WFE1 Created"   write-host "Creating Query Processing Component on WFE1" -ForegroundColor Yellow New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchInstancewfe1 write-host -ForegroundColor Green "Query Processing Component on wfe 1 Created"   Write-Host "Search components on WFE1 Configured ###################################################################" -ForegroundColor Green #============================== WFE1 ============================================================================         ############################### WFE2 ############################################################################   Write-Host "Configuring WFE2" -ForegroundColor Yellow New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $searchInstancewfe2 write-host -ForegroundColor Green "Admin Component Created on WFE1" write-host "Creating Index on WFE2 Component" -ForegroundColor Yellow New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $searchInstancewfe2 -RootDirectory $IndexLocation write-host -ForegroundColor Green "Index Component on WFE2 Created"   write-host "Creating Query Processing Component on WFE2" -ForegroundColor Yellow New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchInstancewfe2 write-host -ForegroundColor Green "Query Processing Component on wfe 2 Created"   Write-Host "Search components on WFE2 Configured ###################################################################" -ForegroundColor Green #============================== WFE2 ============================================================================   $clone.Activate()   #endregion     #region Set Active admin component $ssa | get-SPEnterpriseSearchAdministrationComponent | set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $searchInstanceIndex   #endregion       #region Create search service proxy Write-Host " Creating Proxy..." $searchAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$searchSAName Proxy" -SearchApplication $searchSAName > $null #endregion     #region Set default content access account write-host " Setting default content access account..." Set-SPEnterpriseSearchServiceApplication -Identity $searchSAName -DefaultContentAccessAccountName $defaultContenAccessAccount -DefaultContentAccessAccountPassword $defaultContenAccessAccountPassword #endregion     #region Set Windows services account Write-Host " Setting windows service account..." Set-SPEnterpriseSearchService -Identity $searchSAName -ServiceAccount $windowsService.Username -ServicePassword $windowsServicePassword -ContactEmail $contactEmail #endregion   Write-Host " Search Service Application Provisioned" -ForegroundColor Green   #region Delete default inactive topology Write-Host "Getting inactive topology..." $inactive=Get-SPEnterpriseSearchTopology -SearchApplication Search_Sa |Where {$_.state -eq "Inactive"}     Write-Host "Removing Inactive topology..." Remove-SPEnterpriseSearchTopology -Identity $inactive -Confirm:$false #endregion     write-host -foregroundcolor green "################################################################### Search completed ###################################################################"     08. SearchServiceApplication(2).ps1 (10.76 kb)

Tags:

PowerShell | SharePoint | SharePoint 2013

Export – import alerts

by Robi 9. November 2013 18:23
In my previous blog post I have explained how you can troubleshoot alerts. In this one, I'm just going to post scripts I used for exporting and importing all alerts in a site collection. Here is the script for exporting all alerts in a site collection to a csv file: $site = Get-SPSite "http://2013portal" $alertResultsCollection = @() foreach ($web in $site.AllWebs) { foreach ($alert in $web.Alerts){ $alertURL = $web.URL + "/" + $alert.ListUrl $alertResult = New-Object PSObject $alertResult |Add-Member -type NoteProperty -name "WebUrl" -Value $web.Url $alertResult | Add-Member -type NoteProperty -name "ListURL" -value $alertURL $alertResult | Add-Member -type NoteProperty -name "AlertTitle" -value $alert.Title $alertResult | Add-Member -type NoteProperty -name "ListUrl" -value $alert.ListUrl $alertResult | Add-Member -type NoteProperty -name "List" -value $alert.List $alertResult | Add-Member -type NoteProperty -name "DeliveryChannel" -value $alert.DeliveryChannels $alertResult | Add-Member -type NoteProperty -name "AlertType" -value $alert.AlertType $alertResult | Add-Member -type NoteProperty -name "EventType" -value $alert.EventType $alertResult | Add-Member -type NoteProperty -name "Frequency" -value $alert.AlertFrequency $alertResult | Add-Member -type NoteProperty -name "AlertTime" -value $alert.AlertTime $alertResult | Add-Member -type NoteProperty -name "SubscribedUser" -value $alert.User $alertResultsCollection += $alertResult } } $site.Dispose() $alertResultsCollection  #Export to CSV $alertResultsCollection | Export-CSV C:\Users\sp2013_farm_admin\Desktop\Alerts.csv  And here is the script you can use to import all alerts in one site collection from csv file:  Import-Csv C:\Users\sp2013_farm_admin\Desktop\Alerts.csv |ForEach-Object{ $webUrl=$_.WebUrl $listTitle=$_.List $alertTitle=$_.AlertTitle $subscribedUser=$_.SubscribedUser $alertType=$_.AlertType $deliveryChannel=$_.DeliveryChannel $eventType=$_.EventType $frequency=$_.Frequency   $web=Get-SPWeb $webUrl $list=$web.Lists.TryGetList($listTitle) $user = $web.EnsureUser($subscribedUser) $newAlert = $user.Alerts.Add() $newAlert.Title = $alertTitle $newAlert.AlertType=[Microsoft.SharePoint.SPAlertType]::$alertType $newAlert.List = $list $newAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::$deliveryChannel $newAlert.EventType = [Microsoft.SharePoint.SPEventType]::$eventType $newAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::$frequency if($frequency -ne "Immediate"){ $AlertTime=$_.AlertTime $newAlert.AlertTime=$AlertTime } $newAlert.Update() }    Hope it helps. Robi Vončina

Tags:

SharePoint | SharePoint 2010 | SharePoint 2013

Upgrade Video

by Robi 27. August 2013 10:34
For the Ukrainian SharePoint Conference I recorded this video to present it at my session. I decided to make it public now so please, sit back, relax and enjoy it.    Upgrading to SharePoint 2013 Video

Tags:

SharePoint | PowerShell | SharePoint 2013 | SharePoint 2010

Crawling MySites on https

by Robi 6. August 2013 15:10
Small trick… If you are going to crawl My Sites which are configured on https, you need to set your content source to crawl sps3s://mysites instead of sps3://mysites. If you try to crawl sps3 when your mysites web application is configured with SSL, you get the: »Object not found« Error in your crawl logs.  Hope it helps!!!

Tags:

SharePoint | SharePoint 2013

Picture gallery with Galleria and Content Query Web part

by Robi 13. August 2012 09:56
Following E. Struyf 's Blog for making a picture gallery from the assets library: Making an Image Gallery Inside the Asset Library: Part 1 - E. Struyf 's Blog http://www.estruyf.be/blog/making-an-image-gallery-inside-the-asset-library-part-1 I thought that it has to be a way to get pictures from picture gallery with the Content Query Web Part and modify the results so that it can work for the galleria. So, the first step of course would be to download all the necessary files. To download files go to the galleria we page and extract the zip file. You can copy all files to the Style library, where I made the JS folder to save the jQuery library file, downloaded from the www.jQuery.com web site. Galleria files  Download Galleria http://galleria.io/download/   Screen shot of the Style library\JS folder. For the galleria to work, you will need: Jquery library Galleria.classic.css Galleria.classic.min.js Galleria-1.2.7.min.js Classic-loader.gif Classic-map.png. XSL files Next thing to do is to modify the ContentQueryMain.xsl and ItemStyle.xsl. In ContentQueryMain you need to modify the div in which pictures will be displayed. In order to do that just add the class gallery to the div id=''{concat('cbqwp',$ClientId)}''. You will specify the branding later on for the .gallery class. ContentQueryMain.xsl  In ItemStyle.xsl you need to add a new xsl:template, which will be used for rendering pictures in CQWP. Important part here is to change the variable SafeLinkUrl. So to get the full picture not just the picture thumbnail you need to select the LinkUrl column for the UrlColumnName. ItemStyle.xsl <xsl:template name="ImageGallery" match="Row[@Style='ImageGallery']" mode="itemstyle">      <xsl:variable name="SafeLinkUrl">         <xsl:call-template name="OuterTemplate.GetSafeLink">          <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>         </xsl:call-template>     </xsl:variable>                      <img src="{@LinkUrl}"/> </xsl:template>  Gallery page Next thing to do is to create and modify the web part page where the gallery will be shown. Edit the file in advanced mode in SharePoint Designer 2010 and just after the PlaceHolderMain opening tag add the following code (modify reference to your script files if needed): <link type="text/css" rel="stylesheet" href="../../Style Library/js/galleria.classic.css"/> <script type="text/javascript" src="../../Style Library/js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="../../Style Library/js/galleria.classic.min.js"></script> <script type="text/javascript" src="../../Style Library/js/galleria-1.2.7.min.js"></script> <script type="text/javascript"> $(document).ready(function(){     $(".gallery img").unwrap().unwrap();          $('.gallery').galleria({     width: 700,     height: 467 });     Galleria.loadTheme('../../Style Library/js/galleria.classic.min.js');     Galleria.run('.gallery');  }); </script> This code will add reference to the files in Style library, JavaScript, CSS,… $(".gallery img").unwrap().unwrap(); unwraps the pictures form the <li> tag and <ul> tag which CQWP adds when it displays the pictures and needs to be done so that galleria can step in action and create the actual gallery. Galleria.loadTheme and Galleria.run just runs the galleria to create the picture gallery.  At the end of the page, just after the </asp:content> add the style tag, which will apply background, height and width to the gallery div of the Content Query Web Part. This was set in ContentQueryMain.xsl  <style type="text/css">     .gallery{     width:700px;     height: 472px;     background: #000;     margin:auto;     text-align:center;     } </style> Content Query web part On the page add the CQWP and Edit Web part. For the picture source select the picture gallery where your pictures are saved. You can also specify filter for the pictures. What is important in the CQWP settings is that you apply the ItemStyle you previously created in ItemStyle.xsl called ImageGallery. Save the CQWP settings, save the page and refresh it. And the final result is: Robert Vončina Kompas Xnet d.o.o. robi@kompas-xnet.si

Tags:

SharePoint | SharePoint 2010 | Development

Calendar

<<  March 2017  >>
MonTueWedThuFriSatSun
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar

Page List

Month List