Every system needs a maintenance, configuration changes and other and and actions that cause disturbances in the system.
We can use email to inform users about a planned break or disruptions in the system’s operation. But email is easy to overlook.
In Sitecore the best place to inform about maintenance is Content Editor and Experience Editor – places where content authors spend most of their time working with Sitecore. The best tool to use is of course Sitecore Powershell Extensions (SPE).
To build a proper message you will need a message text, and a placeholder for date and time to inform when exactly maintenance is planned. Let’s start coding.
# Maintenance message
$message = "On {0} from {1} to {2}, your portal will be briefly`
unavailable due to a software update."
# Maintenance period
$dateFrom = Get-Date "2019-12-25 1:00"
$dateTo = $dateFrom.AddHours(1)
$messageToDisplay = $message -F $dateFrom.ToLongDateString(),`
$dateFrom.ToShortTimeString() , $dateTo.ToShortTimeString()
The result of execution:
On Wednesday, December 25, 2019 from 1:00 AM to 2:00 AM,
your portal will be briefly unavailable due to a software update.
You may ask, what about time zones and message translation? Let’s leave it for later. Now the most important part – displaying the message in Content Editor and Experience Editor. You probably think this is the hardest part, but no. It’s a piece of cake, becasue of SPE.
Add SPE module
Adding a new module is very easy. You must go to the ‘Script Library’ and select ‘Module’.

A dialog will be displayed in which you must enter the module name and select three options:
- Content Editor Warning
- Page Editor Notifications
- Shared Functions

The first two options will ensure integration with Content Editor and Experience Editor. Option Shared Functions creates a Function folder where you will add functions common to both notifications. Below you can see a new module structure. Now you have to add three scripts:
- DisplayMaintenanceWarning
- Get-MaintenanceMessage
- DisplayMaintenanceNotification.


Annoing Session Elevation
During work with SPE module you can see annoying request to elevate your session. Read more – how to manage User Access Control in SPE.
Get-MaintenanceMessage
In this function you can add a logic necessary to build a proper maintenance message. You can use code that you create above.
function Get-MaintenanceMessage {
# Maintenance message
$message = "On {0} from {1} to {2}, your portal will be briefly`
unavailable due to a software update."
# Maintenance period
$dateFrom = Get-Date "2019-12-25 1:00"
$dateTo = $dateFrom.AddHours(1)
$messageToDisplay = $message -F $dateFrom.ToLongDateString()`
,$dateFrom.ToShortTimeString() , $dateTo.ToShortTimeString()
return $messageToDisplay
}
Display Content Editor Warning
Script DisplayMaintenanceWarning is responsible for displaing the maintenance message in Content Editor. First we have to import function Get-NotificationMessage and use the returned value as message to display.
Import-Function Get-MaintenanceMessage
$title = "Sitecore Maintenance Message"
$text = Get-MaintenanceMessage
$icon = @{$true="Office/32x32/information.png";$false="Applications/32x32/tools.png"}[$SitecoreVersion.Major -gt 7]
$warning = $pipelineArgs.Add($title, $text);
$warning.Icon = $icon
Display Experience Editor Notification
Script DisplayMaintenanceNotification is responsible for displaying the maintenance message in Experience Editor. Like in a previous case you have to import shared function that will provide a message.
Import-Function Get-MaintenanceMessage
$title = "Sitecore Maintenance Message"
$text = Get-MaintenanceMessage
$icon = @{$true="Office/32x32/information.png";$false="Applications/32x32/tools.png"}[$SitecoreVersion.Major -gt 7]
$warning = New-Object -TypeName Sitecore.Pipelines.GetPageEditorNotifications.PageEditorNotification -ArgumentList $text, "Warning"
$warning.Icon = $icon
$pipelineArgs.Notifications.Add($warning)
Final effect

As you can see create SPE module with simple business logic is easy You can believe me or not it is much faster than writing this post.
The presented solution is a quick win. Now you can add:
- Configuration item – where you can easy setup dates and translate your message.
- Show/hide logic – a simple function to decide if maintenance message should be displayed.
Or you can wait for the next part of this post, and follow me.
Follow @RobsonAutomatorTroubleshooting
If you experience problems displaying the message in Experience Editor, read this post. It describes how to check whether you have the integration with EE is appropriately configured.
1 comment