SharePoint 2016/2013/Online - Sites Health Monitoring By PowerShell Automation

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

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 the maximum possible availability of all the sites.

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

With this background, let’s start with our demo.

In this demo, we have two SharePoint sites in question, as follows.

  • The first site is SharePoint On-Premise Site (Central Administration Site) with URL 
  • While the other site is SharePoint Online Site with URL

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 the DownloadString method of this class to download the HTML of the respective Site Page.

Step 3

Check for possible error messages that a SharePoint page would generally contain in case 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 them that a specific site is down so that they can take appropriate action accordingly.

1

Step 6

This is the initiation function that is having an array of SharePoint Site URLs that require 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 currently 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.