PowerShell Introduction to Administering SharePoint On-Premises & O365

Presented at the Research Triangle PowerShell Users Group, Durham NC, September 17, 2014

As the role of the SharePoint Administrator continues to evolve, as have the tools. PowerShell has become an integral component of the SharePoint Administrator’s tool bag, whether administering SharePoint On-Premises, or as an Office 365 solution. In this session, we’ll look at day-to-day use cases of PowerShell as the primary tool for SharePoint administration, as well as the differences and restrictions between PowerShell for SharePoint On-Premise and O365.

SharePoint 2013 Suite Bar HTML

I recently started looking to replace the default "SharePoint" text on the top of the SharePoint 2013 Suite Bar. What I expected would be a masterpage change actually turned out to be much more simple; enter the big hammer (PowerShell). If you dig through the changes to the SharePoint 2013 Object Model, you'll find an SPWebApplication property called SuiteBarBrandingElementHtml, that does just what it implies... stores the HTML that gets put in the Suite Bar.

We can use some simple PowerShell to grab the SPWebApplication object, set that value to be whatever we want, and update the object; No masterpage or branding/UX changes required.

$webApp = Get-SPWebApplication http://path/to/webapp
$webApp.SuiteBarBrandingElementHtml = "Company Name"

Coincidentally, after I figured this out and searched to see if it had been blogged before, I found this post. Shout out to Mat for documenting it first... that'll teach me to search first.

Unable to display this Web Part, FAST Search Center

I had an oddball issue at a client recently that I hadn't seen before. After installing a fresh FAST for SharePoint 2010 server, configuring all of the services and provisioning a shiny new FAST Search Center, we were met with "Unable to display this Web Part" errors for all of the search web parts. Each time we refreshed the page one of the web parts came to life, so after 4-5 clicks of the F5 key, the search center performed normally. I searched and searched for possible causes, and the ULS logs were practically useless in tracking down a source of the problem. Then I came across this blog post which discusses a change Microsoft made to reduce the XsltTransformTimeOut property for the farm from a value of 2 to a value of 1. This essentially means that none of the XSL can take more than a second to transform, causing the web part to not be displayed. Changing this to a higher value gives the XSL longer to process and solved all of our problems.

$farm = Get-SPFarm
$farm.XsltTransformTimeOut = 3

Note that the reason Microsoft made the change was to reduce the risk of DoS attacks being performed through XSL. This change is likely not recommended for external or public facing environments.

Removing SPSite Property Bag Keys w/ PowerShell

I recently encountered a scenario where it was necessary to remove keys from the property bag of a site collection. Site collection properties are stored within the Properties collection on the RootWeb of the Site, but Properties.Remove(“key”) failed every time we tried it. It turns out that in addition to toggling the AllowUnsafeUpdates flag, you also must update the Properties object, then remove the key from the AllProperties collection (this was the magic piece we were missing).

$site = Get-SPSite http://path/to/site/collection
$web = $site.RootWeb
$web.AllowUnsafeUpdates = "true"
$web.AllowUnsafeUpdates = "false"
$web.AllowUnsafeUpdates = "true"
$web.AllowUnsafeUpdates = "false"

Once you've executed the commands above to remove the script, re-instantiate the Site and Web objects and query the AllProperties collection to ensure your key has been removed.

$site = Get-SPSite http://path/to/site/collection
$web = $site.RootWeb

Service Application Shortcuts

When configuring and managing service applications within SharePoint 2010, I was always frustrated by the number of clicks it takes to get from the Central Administration home page to a given service application, and the number of clicks required to change from one service app to another. As a quick fix to give more direct navigation to service applications, this PowerShell script will add a shortcut to each service application on the default "Resources" list on the Central Administration home page.

Add-PSSnapIn Microsoft.SharePoint.PowerShell -EA 0

$centralAdminWebApp = Get-SPWebApplication -IncludeCentralAdministration | Where {$_.IsAdministrationWebApplication -eq "True"}

$centralAdminSites = $centralAdminWebApp | Get-SPSite

foreach ($centralAdminSite in $centralAdminSites) {
    if ($centralAdminSite.ServerRelativeUrl -eq "/") {
        Write-Host "Central Administration Site Identified";
        $web = $centralAdminSite.RootWeb
        $resourcesList = $web.Lists["Resources"]
        Write-Host "Resources List Identified"

        $serviceApplications = Get-SPServiceApplication
        Write-Host "Service Applications Captured"
        foreach ($serviceApp in $serviceApplications) {
            $manageUrl = $serviceApp.ManageLink.Url
            $manageTitle = $serviceApp.DisplayName

            if ($manageUrl) {
                try {
                    $shortcut = $resourcesList.Items.Add()
                    $shortcut["URL"] = "$manageUrl, $manageTitle"
                    Write-Host " - $manageTitle Shortcut Added"
                } catch {
                    Write-Host " - Error adding shortcut to $manageTitle" -ForegroundColor "Red"