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:
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:
You can get all of the SharePoint content databases of all web applications by skipping parameter -WebApplication in Get-SPContentDatabase cmdlet.
Once the maintenance window is completed, don't forget to clear it!
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.
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:
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:
You can get all of the SharePoint content databases of all web applications by skipping 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.