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 first site is SharePoint On-Premise Site (Central Administration Site) with URL http://sp-2016-dev:2016
- The other site is SharePoint Online Site with URL http://spodevelopment.sharepoint.com
The On-Premises 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, we 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 with the methods to deal with Site Pages
Step 2: Make use of DownloadString Method of this class to download the HTML from the respective Site Page
Step 3: Check for Possible Error Messages that SharePoint Page would generally contain 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.
https://howtodowithsharepoint.files.wordpress.com/2016/10/14.png?w=800
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.
https://howtodowithsharepoint.files.wordpress.com/2016/10/22.png?w=800
Once this automation script executes we can see the following email notification for SharePoint Online Site which is currently down:
https://howtodowithsharepoint.files.wordpress.com/2016/10/42.png?w=800
And there will be no emails for SharePoint On-Premises Site since it is healthy and active as shown below:
https://howtodowithsharepoint.files.wordpress.com/2016/10/32.png?w=800
That is all for this demo.
Hope you find it helpful.