SharePoint Tidbit – SharePoint Maintenance window


Hello All,

Recently had to work with this class for a customer and thought that it is an amazing way to communicate with your end user since you have there direct attention and they can’t ignore it like they might with an email.

The class SPMaintenanceWindow was introduced in SharePoint Server 2013 and continues to be a hidden gem, it provides you with an encapsulated maintenance window message you can post to end users at the content database level.  The maintenance window message is somewhat limited by the fact that you can not compose your own custom message on the status bar, the functionality does allow you to set the start time and end time (NotificationStartDate and NotificationEndDate) the message will be displayed to end users, as well as the start and end time (MaintenanceStartDate and MaintenanceEndDate) of the actual maintenance work, which is used to build the maintenance window text.

A basic message is composed of the following:

.Duration - Maintenance duration, provide the message with day, hour, and minute of how long site will be read only.

.MaintenanceEndDate - Maintenance end date, provides message with date and time that maintenance will end.  Format (MM/DD/YYYY HH:MM:SS AM|PM)

.MaintenanceStartDate - Maintenance start date, provides message with date and time that maintenance will begin.   Format (MM/DD/YYYY HH:MM:SS AM|PM)

.MaintenanceType - Type of the maintenance (MaintenancePlanned or MaintenanceWarning) depending on what you choose you will get a different message delivered to your end user.             

MaintenancePlanned             


 

MaintenanceWarning

 

 

.NotificationEndDate - Notification end date, provides system with end date and time for displaying message.  Format (MM/DD/YYYY HH:MM:SS AM|PM)

.NotificationStartDate - Notification start date, provides system with start date and time for displaying message.  Format (MM/DD/YYYY HH:MM:SS AM|PM)

If we bring it all together it could look like this

$Window = New-Object Microsoft.SharePoint.Administration.SPMaintenanceWindow

$Window.MaintenanceEndDate = “06/01/2018 07:00:00 AM”

$Window.MaintenanceStartDate = “05/31/2018 10:00:00 PM”

$Window.NotificationEndDate = “06/01/2018 07:00:00 AM”

$Window.NotificationStartDate = “05/17/2018 01:00:00 AM”

$Window.MaintenanceType = “MaintenanceWarning”

 

Get-SPContentDatabase | % {

    $_.MaintenanceWindows.Clear()

    $_.MaintenanceWindows.Add($Window)

    $_.Update()

}

You can also, choose to provide a work duration and hyperlink to a location that could perhaps provide a helpdesk ticket number or contact info.  To leverage the hyperlink capability, you must specify a duration. This would add the following lines to the above object.

NOTE: This is optional and not required for feature to function (But come on that is cool)

$maintenanceWindow.Duration = New-Object System.TimeSpan( 0, 9, 0, 0)

$Window.MaintenanceLink = "http://helpdesk.contoso.com/sites/maintenance/pages/213456.aspx”

ProTip:

For an extra cool message you can provide a negative duration and get a message like this

$maintenanceWindow.Duration = New-Object System.TimeSpan( -1, 0, 0, 0)

$Window.MaintenanceLink = "http://helpdesk.contoso.com/sites/maintenance/pages/213456.aspx”


 

If for some reason you need to clear the message before the notification end date you can run this one-liner

Get-SPContentDatabase | % { $_.MaintenanceWindows.Clear(); $_.Update() }

While sending an e-mail works and is the accepted way to pass messages like these, I think this method provides several advantages.   The first being todays information worker is using email less and less and second your message is delivered directly to the user that requires to know this message even if they don’t have email instead of depending on them looking at there inbox or the message being passed by a supervisor.

While I would enjoy having more direct control over the message this class does provide the correct and appropriate wording, while still giving plenty of flexibility.

Pax

Comments (0)

Skip to main content