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 = "http://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       = "http://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 is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

6 thoughts on “SharePoint 2013 Maintenance Window Notifications

  • February 16, 2021 at 8:39 PM

    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
  • June 4, 2015 at 3:25 AM

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

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

    Reply
    • November 8, 2016 at 5:35 PM

      are you saying yes or no?

      Reply
    • December 13, 2016 at 1:36 PM

      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
  • June 3, 2015 at 4:17 AM

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

    Reply
  • May 26, 2014 at 9:24 AM

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

    Reply

Leave a Reply