Powershell to set Notification/maintenance banner in SharePoint sites

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$maintenanceStartDate  = “10/04/2016 11:00:00 AM” # Date when the maintenance will start

$maintenanceEndDate    = “10/04/2016 12:00:00 PM” # Date when the maintenance will stop

$notificationStartDate = “10/04/2016 10:32:00 AM” # Date when the message will start being displayed

$notificationEndDate   = “10/04/2016 12:00:00 PM” # Date when the message will stop being displayed

$maintenanceLink       = “https://exploresharepointfeatures.com/SitePages/Outage.aspx”     # 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

$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

$webAppln = Get-SPWebApplication https://exploresharepointfeatures.com

# To set notification

foreach ($ContentDb in $webAppln.contentdatabases)

{

$ContentDb.MaintenanceWindows.add($maintenanceWindow)

$ContentDb.Update()

}

# To clear notification

foreach ($ContentDb in $webAppln.contentdatabases)

{

$ContentDb.MaintenanceWindows.Clear()

$ContentDb.Update()

}

# To set notification for sites under specific content db

$ContentDB1 = Get-SPContentDatabase -Identity 1244acad-27af-4017-812f-c8dfc3c5ce1a

$ContentDB1.MaintenanceWindows.add($maintenanceWindow)

$ContentDB1.Update()

# To clear notification for sites under specific content db

$ContentDB1 = Get-SPContentDatabase -Identity 1244acad-27af-4017-812f-c8dfc3c5ce1a

$ContentDB1.MaintenanceWindows.Clear()

$ContentDB1.Update()

Advertisements

About jollsam

10 years of experience in SharePoint Development, Administration and Solution/Infrastructure Architecture.
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Powershell to set Notification/maintenance banner in SharePoint sites

  1. sp guru says:

    Is it possible to customize the message here ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s