Adding Service Notices to the SharePoint 2013 Suite Bar using PowerShell

 

Overview:

I was recently tasked with installing an update to a live SharePoint 2013 extranet site that is actively used by staff as well as external clients. Since the update caused our extranet site to be unavailable for several hours, I found myself wishing for a simple but effective way to alert all SharePoint 2013 site users about upcoming scheduled maintenance. I could send e-mails, but prefer not to do so since we have quite a few people who have access to the SharePoint site, but very few active users. Instead of sending out alerts to more than one hundred employees letting them know that a service they may or may not use will be unavailable, I wanted to publish a notice to the SharePoint site itself.

The Problem:

I need to find a way to publish a notice of anticipated service interruptions on every page of my SharePoint 2013 site. This seemed simple enough at first, until I began to consider the fact that I have multiple site collections, each with multiple sites in my extranet Web Application. Users access the site from a wide variety of links, so publishing a notice on the home page would not be effective. Every site has unique permissions, depending on which users need access to the site’s contents, so publishing announcements on a site-by-site basis would be a real chore.

I am using a pretty generic out-of-the-box SharePoint 2013 installation, so my site is using the default Seattle master pages. I thought about customizing the master pages to include a message, but I would have to do the same for every site collection in my Web Application, which seems to be more trouble than it’s probably worth.

My Solution:

A few weeks ago, I ran across this blog post from “Chris on SharePoint” explaining how to change the out-of-the-box “SharePoint” text in the upper left-hand corner of every page in a SharePoint 2013 site into whatever text or image you want to display. This area of the page is known as the Suite Bar, and the left-hand text is the Branding Element of the Suite Bar. When I followed the instructions from the Chris on SharePoint blog, I was able to change the Suite Bar Branding Element for every site and site collection within my Web Application quite easily.

So, as I was thinking about how to notify the few active users about upcoming site maintenance on my SharePoint 2013 site, I thought that this Suite Bar might be just the right place to put in a small notice or warning letting users know about something coming up. I decided to write a PowerShell script that would automatically create the Suite Bar Branding Element HTML for me with just a few variables. This way, I can easily restore the default HTML by just skipping over the variables. But if I want to throw a special notice for users into the Suite Bar, I can just run the script, fill out a few prompts, and, presto, I have a new Suite Bar with a notice visible to all users about upcoming maintenance schedules!

 

Add_Notice_To_SuiteBar.ps1

Notes: This script, when run, will prompt the user to enter the URL of a SharePoint 2013 Web Application and will build the Suite Bar Branding Element HTML to provide both the desired branding element as well as important warnings or notices provided by the user (If any).

#Request the URL of the Web Application to apply changes to (Enter the Top Level Site Collection URL)
$webapplication = Read-Host "Type the URL of the Web Application"
$rootSite = New-Object Microsoft.SharePoint.SPSite($webapplication)
$spWebApp = $rootSite.WebApplication

#Space out a few lines to help users read the prompts more easily
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host "Enter Notice Information below"
Write-Host "Leave blank for default configuration with NO NOTICE"
pause
Write-Host ""
Write-Host ""
Write-Host ""

#Prompt the user for any notices to post in the Suite Bar (Optional: Leave blank for default Suite Bar)
$NoticeType = Read-Host "Enter a one-word type for this notice (""Warning,"" ""Note,"" etc.)"
$NoticeColor = Read-Host "Enter a Hexadecimal Color (Including #) for this Notice"
$FontColor = Read-Host "Enter a Hexadecimal Font Color (Including #) for this Notice"
$NoticeSummary = Read-Host "Describe in a few words (""Site Maintenance scheduled for June 24th."")"
$NoticeURL = Read-Host "Enter a URL where users can read more information"

#Build the Suite Bar…

if ($NoticeColor -ne "")
{
$NoticeColor = "background-color:"+$NoticeColor+";"
}

if ($FontColor -eq "")
{
$FontColor = "color:#FFFFFF;"
}

if ($FontColor -ne "")
{
$FontColor = "color:"+$FontColor+";"
}

$newSuiteBar = "&nbsp;&nbsp;<table cellpadding=""10"" cellspacing=""0""><tr valign=""top""><td style=""font-weight:bold"">"

#Customize your DEFAULT Suite Bar Branding Element Here:
$newSuiteBar = $newSuiteBar+"<a href=""{http://sharepointserver/}"" style=""text-decoration:underline;color:#FFFFFF;"">{Home}</a></td>"

#Build NOTICE into Suite Bar (If provided)
$newSuiteBar = $newSuiteBar+"<td style="""+$NoticeColor+$FontColor+"font-weight:bold;overflow:hidden""><div style=""padding:3px"">"
if ($NoticeType -ne "")
{
$newSuiteBar = $newSuiteBar + $NoticeType + ":"
}
$newSuiteBar = $newSuiteBar+"&nbsp;"+$NoticeSummary

If ($NoticeURL -ne "")
{
$newSuiteBar = $newSuiteBar+"&nbsp;<a href="""+$NoticeURL+""" target=""_blank"" style=""text-decoration:underline;"+$FontColor+""">Read More</a>&nbsp;"
}

$newSuiteBar = $newSuiteBar+"</div></td></tr></table>"

#Apply the new Suite Bar Branding Element to the Web Application
$spWebApp.SuiteBarBrandingElementHtml = $newSuiteBar

#Update the Web Application to ensure the changes take effect
$spWebApp.Update()

#That's All! Check your site to see how it looks!

 

Running the Script:

Copy the code above and paste it into a new plain text document (i.e. Notepad) on any of the SharePoint 2013 servers in your farm. Next, open the SharePoint 2013 Management Shell application as an administrator (Right-click on the app name to get the “Run as Administrator” option to appear):

 

If you have UAC enabled, you’ll have to confirm you want to run this program with administrative privileges:

 

From the SharePoint 2013 Management Shell console, navigate to the directory where your new .ps1 file is stored:

 

Run the script by typing “.\Add_Notice_To_SuiteBar.ps1” (Obviously, change this to whatever filename you gave your script. Just don’t forget the “.\” before the filename):

 

You will be prompted to enter the URL of the Top Level Site Collection in your Web Application:

 

Press enter and follow the on-screen prompts to enter the values for any notices you may have:

There are five optional variables that can be configured using this script:

  1. Enter a one-word type for this notice:

    (Optional)
    This is the first word of your notice, and will indicate to the visitor the severity of the information you are providing. Examples are “Warning,” “Note,” “Notice,” “Alert,” “Caution,” etc.

    In this example: “Notice”

  2. Enter a Hexadecimal color for this Notice:

    (Optional)
    Enter the full hexadecimal color code for the background color of your notice (blank for the default background).

    In this example: “#FFFF00”

  3. Enter a Hexadecimal Font Color for this Notice:

    (Optional)
    Enter the full hexadecimal color code for the font color of your notice (blank for default font color).

    In this example: “#FF0000”

  4. Describe in a few words:

    (Optional)
    Tell users an abbreviated version of your message. Remember that the Suite Bar is not too big, so just give a few words like “Site maintenance this Thursday” or something else brief but descriptive.

    In this example: “Routine Maintenance scheduled for October 12”

  5. Enter a URL where users can read more information:

    (Optional)
    Provide the full URL of a website that has more information about this notice.

    In this example: “http://sharepointserver/Public/10-12-Maintenance.aspx

Once the script has run, you’ll see your Suite Bar Branding Element look like this on every page in your SharePoint 2013 Web Application:
100413_2047_AddingServi7.png

 


That’s all for today…now get out there and Write the Web!

Leave a Reply

Your email address will not be published. Required fields are marked *