SharePoint 2013 Maintenance Window Notifications

SharePoint 2013 introduced a new class called SPMaintenanceWindow.  SPMaintenanceWindow encapsulates a 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 do is set the start 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.  You can also, optionally, choose to provide a work duration and hyperlink to a location that could provide additional details.  To leverage the hyperlink capability, you must specify a duration.

To better understand the types of messages you can craft to users, below are samples of some of the different message options, and the corresponding PowerShell variables used to create the message.  The PowerShell code at the end of the page will leverage the sample variables and set the message on every content database in the SharePoint 2013 farm.

Single Day Maintenance Planned

image

 $maintenanceStartDate  = "9/28/2013 08:00:00 AM" # Date when the maintenance will start
$maintenanceEndDate    = "9/28/2013 02:00:00 PM" # Date when the maintenance will stop
$notificationStartDate = "9/23/2013 06:00:00 AM" # Date when the message will start being displayed
$notificationEndDate   = "9/28/2013 10:00:00 PM" # Date when the message will stop being displayed
$maintenanceLink       = ""                      # This link will only appear if the maintenance duration is defined.
$maintenanceType       = "MaintenancePlanned"    # OPTIONS ARE: MaintenancePlanned | MaintenanceWarning
$readOnlyDays          = 0   # duration days
$readOnlyHours         = 0   # duration hours. 
$readOnlyMinutes       = 0   # duration minutes only appears if days and minutes are both zero

Multi-day Maintenance Planned

image

 $maintenanceStartDate  = "9/27/2013 08:00:00 AM" # Date when the maintenance will start
$maintenanceEndDate    = "9/28/2013 02:00:00 PM" # Date when the maintenance will stop
$notificationStartDate = "9/23/2013 06:00:00 AM" # Date when the message will start being displayed
$notificationEndDate   = "9/28/2013 02:00:00 PM" # Date when the message will stop being displayed
$maintenanceLink       = ""                      # This link will only appear if the maintenance duration is defined.
$maintenanceType       = "MaintenancePlanned"    # OPTIONS ARE: MaintenancePlanned | MaintenanceWarning
$readOnlyDays          = 0   # duration days
$readOnlyHours         = 0   # duration hours. 
$readOnlyMinutes       = 0   # duration minutes only appears if days and minutes are both zero

Single Day Maintenance Warning

image

 $maintenanceStartDate  = "9/27/2013 08:00:00 AM" # Date when the maintenance will start
$maintenanceEndDate    = "9/27/2013 02:00:00 PM" # Date when the maintenance will stop
$notificationStartDate = "9/23/2013 12:00:00 AM" # Date when the message will start being displayed
$notificationEndDate   = "9/27/2013 02:00:00 PM" # Date when the message will stop being displayed
$maintenanceLink       = ""                      # This link will only appear if the maintenance duration is defined.
$maintenanceType       = "MaintenanceWarning"    # OPTIONS ARE: MaintenancePlanned | MaintenanceWarning
$readOnlyDays          = 0   # duration days
$readOnlyHours         = 0   # duration hours. 
$readOnlyMinutes       = 0   # duration minutes only appears if days and minutes are both zero

Multi-day Maintenance Warning

image

 $maintenanceStartDate  = "9/27/2013 08:00:00 AM" # Date when the maintenance will start
$maintenanceEndDate    = "9/28/2013 02:00:00 PM" # Date when the maintenance will stop
$notificationStartDate = "9/23/2013 06:00:00 AM" # Date when the message will start being displayed
$notificationEndDate   = "9/28/2013 02:00:00 PM" # Date when the message will stop being displayed
$maintenanceLink       = ""                      # This link will only appear if the maintenance duration is defined.
$maintenanceType       = "MaintenanceWarning"    # OPTIONS ARE: MaintenancePlanned | MaintenanceWarning
$readOnlyDays          = 0   # duration days
$readOnlyHours         = 0   # duration hours. 
$readOnlyMinutes       = 0   # duration minutes only appears if days and minutes are both zero

Single Day Maintenance Warning With a Duration Greater Than Zero

image

 $maintenanceStartDate  = "9/28/2013 08:00:00 AM" # Date when the maintenance will start
$maintenanceEndDate    = "9/28/2013 02:00:00 PM" # Date when the maintenance will stop
$notificationStartDate = "9/23/2013 06:00:00 AM" # Date when the message will start being displayed
$notificationEndDate   = "9/28/2013 02:00:00 PM" # Date when the message will stop being displayed
$maintenanceLink       = ""                      # This link will only appear if the maintenance duration is defined.
$maintenanceType       = "MaintenanceWarning"    # OPTIONS ARE: MaintenancePlanned | MaintenanceWarning
$readOnlyDays          = 1   # duration days
$readOnlyHours         = 6   # duration hours. 
$readOnlyMinutes       = 0   # duration minutes only appears if days and minutes are both zero

Single Day Maintenance Warning With a Duration Less Than Zero and a Hyperlink

image

 $maintenanceStartDate  = "9/28/2013 08:00:00 AM" # Date when the maintenance will start
$maintenanceEndDate    = "9/28/2013 02:00:00 PM" # Date when the maintenance will stop
$notificationStartDate = "9/23/2013 06:00:00 AM" # Date when the message will start being displayed
$notificationEndDate   = "9/28/2013 02:00:00 PM" # Date when the message will stop being displayed
$maintenanceLink       = "http://www.bing.com"   # This link will only appear if the maintenance duration is defined.
$maintenanceType       = "MaintenanceWarning"    # OPTIONS ARE: MaintenancePlanned | MaintenanceWarning
$readOnlyDays          = -1  # duration days
$readOnlyHours         = 0   # duration hours. 
$readOnlyMinutes       = 0   # duration minutes only appears if days and minutes are both zero

Single Day Maintenance Warning With a Duration Greater Than Zero and a Hyperlink

image

 $maintenanceStartDate  = "9/28/2013 08:00:00 AM" # Date when the maintenance will start
$maintenanceEndDate    = "9/28/2013 02:00:00 PM" # Date when the maintenance will stop
$notificationStartDate = "9/23/2013 06:00:00 AM" # Date when the message will start being displayed
$notificationEndDate   = "9/28/2013 02:00:00 PM" # Date when the message will stop being displayed
$maintenanceLink       = "http://www.bing.com"   # This link will only appear if the maintenance duration is defined.
$maintenanceType       = "MaintenanceWarning"    # OPTIONS ARE: MaintenancePlanned | MaintenanceWarning
$readOnlyDays          = 1   # duration days
$readOnlyHours         = 6   # duration hours. 
$readOnlyMinutes       = 0   # duration minutes only appears if days and minutes are both zero

Multi-day Maintenance Warning with Duration Less Than Zero and a Hyperlink

image

 $maintenanceStartDate  = "9/28/2013 08:00:00 AM" # Date when the maintenance will start
$maintenanceEndDate    = "9/29/2013 10:00:00 PM" # Date when the maintenance will stop
$notificationStartDate = "9/23/2013 06:00:00 AM" # Date when the message will start being displayed
$notificationEndDate   = "9/29/2013 10:00:00 PM" # Date when the message will stop being displayed
$maintenanceLink       = "http://www.bing.com"   # This link will only appear if the maintenance duration is defined.
$maintenanceType       = "MaintenanceWarning"    # OPTIONS ARE: MaintenancePlanned | MaintenanceWarning
$readOnlyDays          = -1  # duration days
$readOnlyHours         = 0   # duration hours. 
$readOnlyMinutes       = 0   # duration minutes only appears if days and minutes are both zero

This PowerShell code leverages the variables used in the samples above to set the message on every content database in the farm.

 $maintenanceWindow = New-Object Microsoft.SharePoint.Administration.SPMaintenanceWindow
$maintenanceWindow.MaintenanceEndDate    = $maintenanceEndDate
$maintenanceWindow.MaintenanceStartDate  = $maintenanceStartDate
$maintenanceWindow.NotificationEndDate   = $notificationEndDate
$maintenanceWindow.NotificationStartDate = $notificationStartDate
$maintenanceWindow.MaintenanceType       = $maintenanceType
$maintenanceWindow.Duration              = New-Object System.TimeSpan( $readOnlyDays, $readOnlyHours, $readOnlyMinutes, 0)
$maintenanceWindow.MaintenanceLink       = $maintenanceLink

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

If you need to clear the maintenance window message queue, perhaps your maintenance window was cancelled, execute this PowerShell code.

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