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.

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.

Stay tuned.:)

SharePoint 2016: Forms Based Authentication – Part 1

Form Based Authentication (FBA) is one of the Authentication Mode supported by SharePoint that allows us to implement our own authentication mechanism and helps to extend a SharePoint Site for Non-Active Directory (AD) Users.

While SharePoint default installation employs Active Directory to query User Profiles and to authenticate the Users using Windows Authentication, FBA uses the custom database hosted in conjunction with AD to store User’s Credentials and the authentication in this case takes place using database query to the FBA Custom Database for FBA User Profiles.

FBA becomes really important when it comes to the requirements where we need to expose SharePoint to outer world. For example: Sharing documents with your Clients and Vendors or else.

In this article we will see to all the steps involved in implementing FBA with SharePoint and we can depict the process as per the Process Diagram below-

Process Diagram

1

Step 1: Provision Web Application

In order to start with implementing FBA we need a Web Application and Site Collection hosted inside it. I have created both Web Application & a Site Collection using SharePoint UI.

23

Step 2: Provision Membership Database

In order to provision Membership Database for storing user credentials Microsoft has been provided with a utility “aspnet_regsql.exe”.

In order to execute this utility we follow the below steps:

  • Launch SharePoint 2016 Management Shell
  • Run the following commands:

CD \Windows\Microsoft.Net\Framework64\v4.0.30319

          .\aspnet_regsql

4

Once we execute the commands above the Database Configuration wizard come up

  • Click Next on Welcome Screen

5

  • Choose “Configure SQL Server for application services” on the Setup Option Screen
  • Click Next

6

  • Enter database details on Server and Database Selection Screen
  • Enter SQL Database Server Name

You can specify the database name or leave it as default which will create a database by the name “aspnetdb”

7

  • On the confirmation Page you can see the Database Server Name and Database Name as well that is going to be provisioned
  • Click Next

8

This will provision the Membership Database to SQL Server

  • Click Finish on the completion screen

9

Now in order to verify if Membership Database has been created successfully or not and to allow requirement permissions for SharePoint Admin account.

Note: Granting permission explicitly on “aspnetdb” is necessary for SharePoint Admin Account as this is just a SQL Server Database with SharePoint having no knowledge of it. So by default SharePoint Admin Account won’t be allowed to get access to this database.

  • Login in to SQL 2014 Management Studio

10

  • Expand the Database Node and see for “aspnetdb” database

11

In order to grant permissions to the SharePoint Farm Account which is “Prashant\Administrator” in here follow the steps below:

  • Expand the Security Node
  • Expand the Logins Node
  • Locate the account you want to grant permissions
  • Right Click it
  • Select Properties

12

  • On the Account Properties Screen Select “User Mapping”

13

  • Select the “aspnetdb” Database
  • Select “db_owner” Role
  • Click OK to save the changes to SQL Server

14

With this we are all done for this demo.

In this article we have covered Step 1 & 2. We will look for Step 3 & 4 in upcoming article on Configuring FBA for SharePoint.

Stay tuned. 🙂