SharePoint 2013 Maintenance Window Notifications

In continuation to my earlier post: Site Under Maintenance Page for SharePoint, while the solution serves the purpose perfectly by displaying a typical “Site under maintenance” page during occasions like SharePoint patching, upgrade, etc. wouldn’t it be nice to intimate end-users about the planned maintenance window in advance?

Well, SharePoint 2013 brings a new class SPMaintenanceWindow to support planned maintenance windows. Here is how it works: Prior to planned maintenance window schedules, You set the maintenance window on SharePoint content databases to display a notification to end users about the Planned maintenance window.

Once user hit SharePoint sites they’ll see a notification banner on SharePoint 2013 sites notification area (On Top).  Here is the PowerShell script to set maintenance window notification in SharePoint 2013:

How to Create SharePoint 2013 maintenance window notifications?

Add-PSSnapin Microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$WebAppURL = "https://sharepoint.crescent.com"

#Get all content databases of the web application 
$ContentDbs = Get-SPContentDatabase -WebApplication $WebAppURL

#Create maintenance Window Object
$MaintenanceWindow = New-Object Microsoft.SharePoint.Administration.SPMaintenanceWindow
$MaintenanceWindow.MaintenanceEndDate    = "12/31/2013 11:59:00 PM"
$MaintenanceWindow.MaintenanceStartDate  = "12/29/2013 12:00:00 AM"
$MaintenanceWindow.NotificationEndDate   = "12/31/2013 11:59:00 AM"
$MaintenanceWindow.NotificationStartDate = "12/25/2013 08:00:00 AM"
$MaintenanceWindow.MaintenanceType       = "MaintenancePlanned"  #Another Option: MaintenanceWarning
$MaintenanceWindow.Duration              = "03:00:00:00" #in "DD:HH:MM:SS" format
$MaintenanceWindow.MaintenanceLink       = "https://support.crescent.com/faq/SPMaintenanceWindow"

#Add Maintenance window for each content database of the web application
$ContentDbs | ForEach-Object  {
  #Clear any existing maintenance window
  $_.MaintenanceWindows.Clear()
 
  #Add New Maintenance Window
  $_.MaintenanceWindows.add($MaintenanceWindow)
  $_.Update() 
}

The above script gets all content databases associated with the provided web application and sets the maintenance window for site collections residing on them. Here is the script in action:

Maintenance Windows in SharePoint 2013

You can get all the SharePoint content databases of all web applications by skipping the parameter -WebApplication in Get-SPContentDatabase cmdlet.

$ContentDbs = Get-SPContentDatabase

Once the maintenance window is completed, don’t forget to clear it!

Get-SPContentDatabase | foreach-object {
    $_.MaintenanceWindows.Clear()
    $_.Update()
 }

BTW, even though the banner says: Sites will be in Read-only mode, actually the script it self doesn’t set sites so. We’ve to make the site collections read-only explicitly, if needed.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

6 thoughts on “SharePoint 2013 Maintenance Window Notifications

  • We generally keep all databases but one offline for all webapps so that we have an idea of where no site collections are going to be created. Just realized that all of a webapps databases have to be started (ready) in order for the maintenance banner to work properly.

    Reply
  • This post says you can’t customize the text, but there is an option to add in a link for more information.

    https://blogs.msdn.com/b/josrod/archive/2013/09/30/sharepoint-2013-maintenance-window-notifications.aspx

    Reply
    • are you saying yes or no?

      Reply
    • Its set based on “MaintenanceType” parameter. However, You can’t customize it further. E.g. You can’t display any other message of your choice!

      Reply
  • Can I customize the displayed text ? e.g. search not working correct?

    Reply
  • It’s a cool feature. Thanks for sharing it.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *