Showing posts with label maintenance banner. Show all posts
Showing posts with label maintenance banner. Show all posts

Wednesday, November 2, 2016

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()