SharePoint 2016: How to configure Search Service Application using PowerShell

In this article we will discuss how to provision Search Service Application for SharePoint 2016 using PowerShell

During this whole article I will guide you steps involved in provisioning Search Application along with the corresponding PowerShell Script

Here the steps that we will explore in the upcoming section-

1

2

3

Though we can provision Search Application from Central Admin as well but the purpose here is to demonstrate the use of PowerShell commands required to provision Search Application so that’s what we will do.

First let’s go to Central Admin to ensure that there is no existing instance of Search Service Application has been provisioned earlier

Under Application Management -> Click on “Manage Service Applications”

4

Here we can see what all Service Application Instances provisioned earlier and we can see there are none

5

Now launch SharePoint Management Shell to run the required PowerShell commands

6

We will run the PowerShell commands in the following order to make sure each Sub component provisioned as desired.

Step 1: Provision Service Application Instance

In this Step we will first provision Search Service Application using the following cmdlet-

$sa = New-SPEnterpriseSearchServiceApplication -Name "Search Service Application" -DatabaseName "SearchDB" –ApplicationPool  "SecurityTokenServiceApplicationPool"

Make sure Application Pool should exists before you run this command else it will fail since this cmdlet wont’ add the Application Pool automatically

7

Step 2: Provision Application Proxy

Then we need to provision Application Proxy by using following cmdlet referring the Service Application Instance provisioned in the previous step

New-SPEnterpriseSearchServiceApplicationProxy -Name "Search Service Application Proxy" -SearchApplication $sa

8

Step 3: Validate Service Instance

Next step is to validate that the Service Instance is online and to do so we can use the following cmdlet

Get-SPEnterpriseSearchServiceInstance -local

9

Step 4: Clone Topology

Next step is to clone the topology which is required in order to make any changes to the search topology in a search installation that has items in the search index

As per Microsoft recommendation around this you need to modify this new topology object, which is a clone of the active topology, by adding or removing search components. After you have made the changes to the clone topology object, you have to activate this clone to have this topology in action.

$clone = $sa.ActiveTopology.Clone()

10

Step 5: Get Search Service Instance Server Name

This Server name is required in the upcoming steps to it is wise to make use of the following cmdlet to retrieve the server name

Get-SPEnterpriseSearchServiceInstance| Select Server

11

Step 6: Get Search Service Instance

Then we get handle over the search service instance running on the respective server using the following cmdlet

$si = Get-SPEnterpriseSearchServiceInstance | ?{$_.Server -match "SP-2016-Dev"}

This reference object will be used in the upcoming steps

12

Step 7: Provision Admin Component

Next step is to provision a new Admin Component for the given topology and search service instance using the following cmdlet. This cmdlet is using reference to search service instance we get in the earlier steps

New-SPEnterpriseSearchAdminComponent -SearchTopology $clone -SearchServiceInstance $si

13

Step 8: Provision Processing Component

Next step is to provision new content processing component for the given topology and search service instance using the following cmdlet

New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $clone -SearchServiceInstance $si

14

Step 9: Provision Analytics Component

Then we have to provision new analytics processing component for the given topology and search service instance using the following cmdlet

New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $clone -SearchServiceInstance $si

15

Step 10: Provision Crawl Component

Then we have to provision new crawl component for the given topology and search service instance using the following cmdlet

New-SPEnterpriseSearchCrawlComponent -SearchTopology $clone -SearchServiceInstance $si

16

Step 11: Provision Index Component

Then we have to provision new index component for the given topology and search service instance using the following cmdlet

New-SPEnterpriseSearchIndexComponent -SearchTopology $clone -SearchServiceInstance $si -IndexPartition 0 -RootDirectory C:\SearchIndex\

RootDirectory: Specifies the root directory that will hold the index location for the new search index component. If you plan to isolate the index on dedicated discs in order to avoid I/O contention that may leads to performance degradation as it might be a risk that index filling up the OS disk and ruin the overall server performance.

17

Step 12: Provision Query Component

And finally we have to provision new query processing component for the given topology and search service instance using the following cmdlet

New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $clone -SearchServiceInstance $si

18

Step 13: Activate New Topology

Once all the components has been added to the new topology, activate it by using following cmdlet

$clone.Activate()

19

Step 14: Clean Inactive Topologies

Finally we have to clean all the inactive topologies associated with a search service application. We can perform this clean by using the following the code using “Remove-SPEnterpriseSearchTopology” cmdlet

foreach($tp in (Get-SPEnterpriseSearchTopology -SearchApplication $sa | ?{$_.State -eq "Inactive"}))
{    
   Remove-SPEnterpriseSearchTopology -Identity $tp -Confirm:$false
}

20

Step 15: Change Default Content Access Account

And we can change the default content access account by using the following code

$sa = Get-SPEnterpriseSearchServiceApplication

$content = New-Object Microsoft.Office.Server.Search.Administration.Content($sa)

$content.SetDefaultGatheringAccount("<Enter User Name>", (ConvertTo-SecureString "<Enter Password>" -AsPlainText -Force))

21

Now it is time to validate if search service application has been provisioned correctly.

Go to Central Admin -> Manage Service Applications

We can see a new Search Application has been provisioned successfully by clicking the Search Service Application Link

22

And we can see all the component are provisioned and running as expected.

23

Also we can validate the SQL Databases that has been provisioned during creating new search service applications as shown in the following screenshots

242526

Hope you find it helpful.

Advertisements

SharePoint 2013/2016: How to Find Duplicate Records in SharePoint List

During one of my assignments I have come across a situation where we need to fix data issues in SharePoint Lists.

One of the issues that we found was presence of duplicate data. In order to fix that problem in hand I had developed a Powershell Script to find out duplicate data based on a specific or a group of columns.

For the sake of demo, I have added a SharePoint List with some duplicate records in it as shown below:

1

Now let’s look into the code to understand implementation details-

In Step 1 we are getting references of the Site and Web where the SharePoint List resides

In Step 2 we are splitting the list of columns based on which we want to find out the duplicate data

We can see there are two input variables “ColumnToValidate” and “ColumnToDisplay”. “ColumnToValidate” provides columns based on which duplicity needs to be checked while “ColumnToDisplay” contains the list of columns that needs to be the part of data export.

In Step 3 we are creating the export folder that will hold the CSV files exported with duplicate records

In Step 4 we are creating the list object that will give the handle on the list which needs to be validated

2

In Step 5 we are getting list of Items from SharePoint List and grouping them based on the validation columns

In Step 6 we are creating the directory for export files

In Step 7 we are exporting all the groups which is having item count greater than 1 (this logic identifies the duplicate items)

3

That is all for the code.

Now we will see the variation in outputs depending on the columns specified for duplicacy check

In Step 8 we specify the validation and display columns, for the first execution we will check duplicate values in “Title” column

In Step 9 we are calling the “Get-DuplicateListItems” function to find the duplicate values

4

After the function executed successfully we can see the following output.

In Step 10 we can see the output of this excution and can see 6 items found which duplicate in Title Column

5

In Step 11 we can see the CSV file that is exported by the execution considering “Title” Column to be validated.

6

In Step 12 we can see the output file and can notice duplicate values in “Title” Column

7

In Step 13 we have changed the list of columns to be validated. In this second execution I have added another column “Role”.

Now the list will be validated for duplicity based on the combination of “Title & Role” Columns

8

In Step 14 we can see the output of this excution and can see 4 items found which duplicate in “Title & Role” Columns

9

In Step 15 we can see the CSV file that is exported by the execution considering “Title & Role” Column to be validated

10

In Step 16 we can see the output file and can notice duplicate values in “Title & Role” Column

11

In Step 17 we have changed the list of columns to be validated. In this second execution I have added another column “Location”.

Now the list will be validated for duplicity based on the combination of “Title & Role & Location” Columns

12

In Step 18 we can see the output of this excution and can see 2 items found which duplicate in “Title & Role & Location” Columns

13

In Step 19 we can see the CSV file that is exported by the execution considering “Title & Role & Location” Column to be validated

14

In Step 20 we can see the output file and can notice duplicate values in “Title & Role & Location” Column

15

This is a very simple technique that can be used to fix one of the issues with SharePoint List data.

Hope you find it helpful.

SharePoint 2016/2013 : Event Log Monitoring by PowerShell Automation

This article is based on the requirement I recently encounter where I was required to monitor a specific exception type and if it occurs the Admins should be notified at the same time.

In this demo I am considering a scenario that if ever we have encountered an Event ID “1101” that would mean the SharePoint Site or any related service is down and in that case the Administrators will get Email Notifications automatically.

1

In order to accomplish this let start with writing a PowerShell function “Monitor-Event-Logs” as shown in Step 1

In Step 2 we are making use of “Get-EventLog” commandlet by instructing it to get the top 1 latest Application Log where the Event ID = “1101”

We can check for Event Object for null and if it returns the data  we prepare the Email Content comprising of relevant data in as shown in Step 3

In Step 4 we are sending Email Notification to the Administrators by using another generic function “Send-Email”

23

There is an external function “Execute-Process” that will call the “Monitor-Event-Logs” function by passing required Event ID as shown in Step 5

In Step 6 we are initializing the required variables pointing to the email ids of the respective contact persons

Finally in Step 7 we will call the “Execute-Process” function that will drive the whole mechanics.

4

Once the function gets executed we can see the email arrived notifying the error to the administrators as shown below:

56

To make this process more intuitive I got this script scheduled using Windows Task Scheduler to run on a specific time intervals and scan the logs for specific Event IDs.

In my actual implementation I design the “Monitor-Event-Logs” function to accept an array of Event IDs to be monitored so you can try it that way depending on your requirements.

Hope you find it helpful.

 

 

 

SharePoint 2016/2013/Online: Sites Health Monitoring by PowerShell Automation

It is not uncommon that we need to perform health monitoring on SharePoint Sites to ensure that we have stable and healthy SharePoint Farms and to ensure maximum possible availability of all the sites.

In this article we will discuss a simple yet powerful automation technique using PowerShell that will try ping the Site and if gets failed it will send the email notifications to the designated SharePoint Admins for the Site.

With this background let’s start with the demo…

In this demo we have two SharePoint Sites in Question as follows-

The On-Premise site is up and running while SharePoint Online Site is down and unavailable due to some technical reasons

In order to automate this monitoring process I have written a simple function in PowerShell as explained below-

Step 1: Create an Object of System.Net.WebClient Class. This object will provide us the methods to deal with Site Pages

Step 2: Make use of DownloadString Method of this class to download the html of the respective Site Page

Step 3: Check for Possible Error Messages that SharePoint Page would generally contains in case of Site is not accessible by making use of Wild Card Search using Contains Method

Step 4 & 5: We are sending emails to the SharePoint Admins Informing that a specific site is down, so that they can take appropriate actions accordingly.

1

Step 6: This is the initiation function that is having an array of SharePoint Site URLs that requires monitoring.

Step 7: This function will call for Step 1 to Step 5 for each SharePoint Site URL in a periodic manner and keep on circulating the notifications in case of health issues with SharePoint Sites.

2

Once this automation script executes we can see the following email notification for SharePoint Online Site which is currenly down:

4

And there will be no emails for SharePoint On-Premise Site since it is healthy and active as shown below:

3

That is all for this demo.

Hope you find it helpful.

SharePoint 2016: Forms Based Authentication – Part 4

In the previous article SharePoint 2016: Forms Based Authentication – Part 3 of this series on implementing FBA with SharePoint we saw the execution of Step 5 for the process.

In this last article of this series we are going to see the execution of Step 6 & 7 and for the sake of quick review I am putting up the process diagram again in here.

Process Diagram

1

Step 6: Add External Users

  • Go to IIS
  • Select the Web Application on the left navigation pane
  • Click on “.Net Users” on the right section

2

Sometimes you might encounter the following error, this happens because the Default Provider is not set at the time you are trying to Add Users

3

In order to set the default provider you need to click on the “Set Default Provider” link under Actions Pane on the right

4

Select the membership provider as we configured in the earlier steps

5

Now you can add the users.

Click on the “Add” Link under the Actions Pane

6

Adding user information as needed

7

Click “Next”

8

Click “Finish”

And we can see the first FBA user in our system

9

Step 7: Test Forms Based Authentication

Browse the Web Application Via browser

We can see the Selection Window for the choosing the preferred Authentication mechanism

10

Let’s choose Windows Authentication first since we did not give explicit permissions to the FBA User yet, that is why system won’t allow the user to login to the SharePoint Site.

11

And being a authenticated Windows User we are good to go and able to see the Web Application Home Page

Then click on “Site Settings”

12

Click on “People and groups”

13

Click on “Add Users” to add new user to the desired security group.

In here I am adding new user to the Members Groups.

14

Type the name of the FBA user that you have added

In here the FBA User name is “FBAUser”

15

Share the site with FBA user

16

We can see the FBA User added to the Group

17

Now when we are going to browse the Web Application and go with Forms Based Authentication

Choosing this setting will present default login page as we selected in the earlier steps while enabling Web Application with FBA.

Enter FBA user name & password

18

And since we granted the permission to this FBA User in the SharePoint Site, SharePoint allows you to login to the site using FBA user credentials.

19

That is all for this series.

Hope you find it helpful.

SharePoint 2016: Forms Based Authentication – Part 3

In the previous article SharePoint 2016: Forms Based Authentication – Part 2 of this series on implementing FBA with SharePoint we saw the execution of Steps 3 & 4 for the process.

In this article we are going to see the execution of Step 5 and for the sake of quick review I am putting up the process diagram again in here.

Process Diagram

1

Step 5: Configure Authentication Provider

In this step we will associate the Membership Provider with the Web Application that we want to enable with Form Based Authentication

  • Go to Central Administration
  • Click on Manage Web Application

2

  • Select the Web Application
  • Click on “Authentication Providers” link in the ribbon bar

3

  • Click on the Zone “Default”

4

On the Authentication Provider Screen

  • Check “Enable Forms Based Authentication (FBA)”
  • Specify the Membership Provider Name “SPMembership” that we configured previously
  • Specify the Role Manager Name “SPRoles” that we configured previously

5

Under “Sign In” Page Section you can choose to configure a Custom Sign Page if you need or you can proceed with Default Sign Page provided by SharePoint OOB.

In this case I am going along with Default Sign Page offered by SharePoint OOB.

6

That is it for this part of the demo.

I will see you guys in the next article covering Steps 6 & 7 as follows-

SHAREPOINT 2016: FORMS BASED AUTHENTICATION – PART 4

Hope you find it helpful.

 

SharePoint 2016: Forms Based Authentication – Part 2

In the previous article SharePoint 2016: Forms Based Authentication – Part 1 of this series on implementing FBA with SharePoint we saw the execution of Steps 1 & 2 for the process.

In this article we are going to see the execution of Steps 3 & 4 and for the sake of quick review I am putting up the process diagram again in here.

Process Diagram

1

Step 3: Configure IIS

  • Start IIS Manager with Admin rights

2

  • Select IIS Server Name on the left navigation
  • Click on the “Connection Strings”

3

  • Click on Add

4

  • On the “Add Connection String” Screen
  • Enter name of Connection String
  • Enter SQL Server Instance Name
  • Enter Database Name
  • Verify the Connection String and make sure it is correctly build up

5

Once done with the process we can see to the Connection String created

6

Select IIS Server Name on the left navigation and Click the “Providers”

7

  • Select Feature “.Net Roles” from the dropdown
  • Click Add

8

  • On the “Add Provider”
  • Select Type as “SqlRoleProvider”
  • Enter Name as appropriate
  • Enter Connection String Name as appropriate
  • Enter Application Name as “/”
  • Click OK

9

  • Select Feature “.Net Users” from the dropdown
  • Click Add

10

  • On the “Add Provider” Screen
  • Select Type as “SqlMembershipProvider”
  • Enter Name as appropriate
  • Configure behavior of the Membership Provider
  • Choose Connection String Name we created earlier under Data Section
  • Scroll down to configure more settings

11

Enter “/” as Application Name under General Section

12

  • Expand the Web Application from the left navigation
  • Click on the “Providers” from the right hand side

13

Configure “Providers” (Roles & Membership Providers) as shown above since the steps are exactly same so I am not repeating it.

I am putting up the screen shots here for your quick reference

1415161718

Step 4: Modify Web.Config

In the IIS select the Web Application that you want to implement with FBA

  • Click on “Explore”

19

This will open the Virtual Directory for the Web Application

Edit the Web.Config file for the Web Application using Visual Studio

20

Now locate “PeoplePickerWildcards” Section as shown below

21

Specify the name of membership provider “SPMembership” that we have configured in steps above

22

With this we are all done for this demo.

In this article we have covered Step 3 & 4. We will look for Step 5 in upcoming article on Configuring FBA for SharePoint as follows-

SHAREPOINT 2016: FORMS BASED AUTHENTICATION – PART 3

Stay tuned.:)