Activate Feature for All Sites in a Web Application

Posted by on February 21, 2012 at 10:32 am. No comments

Recently I deployed a custom branding feature stapler for one of my customers migrating from 2007 to 2010. As part of the branding feature we had custom layouts and design on the My Site host and user personal sites. New personal content sites created automatically had some custom branding applied by swapping out master pages and adding some linked CSS style sheets to the Style Library.

The solution works great for new personal sites on creation, but migrated sites still had the old look and feel. I wrote the branding feature in a way that it is visible to users and can be activated on a site (sp-web). Since I’m not about to go activate the feature manually on litterally thousands of sites, I put together some handy script to do it for me!

You first need to generate an xml file containing all the sites you want to work with. I’m sure there’s some PowerShell that would do the same thing but I already know this stsadm command will work.

stsadm -o enumsites -url http://mysitehosturl > mysites.xml

Once you have this XML file, feed it into this PowerShell scripts to activate your site feature. Note you’ll need to know the feature’s GUID in order to make it work.


## Enable feature on all sites in site collection
## This script takes the output from the stsadm -o enumsites command (xml)
## Run 'stsadm -o enumsites' first to generate the xml which lists all the site collections for the database

function ActivateFeature([string]$url){
 $featId = "7a8597ff-67a7-473e-b2f5-46d5b504643b"
 $feat = "BrandingTheme_MasterPageDeploymentFeature"

 $site = Get-SPSite $url
 $site | Get-SPWeb -limit all | ForEach-Object {
 if (!$_.Features[$feat]) {
 #Get-SPFeature -Identity $feat | Write-Host $_.Enabled
 try{
 Enable-SPFeature -Identity $feat -Url $_.Url
 }
 catch{
 Write-Host "Feature may already enabled"
 }
 }
 }
}

Write-Host "Getting sites xml file..."
1$config = Get-Content $args[0]
if($config -eq $null -or $err)
 {throw "unable to read xml file. Use stsadm.exe -o enumsites to generate xml"}

Write-Host "Number of site collections: " $config.Sites.Count
[System.Xml.XmlNodeList] $navElements = $config.SelectNodes("/Sites/Site")

foreach ($navElement in $navElements)
{
 $url = $navElement.GetAttribute("Url")
 Write-Host "Appling branding to $url"
 ActivateFeature $url
}

Download the PowerShell script in a .zip file here.

Alternatively you could use SharePoint Manager 2010 to activate the feature without needing to browse to the site. This is still a very manual process but a great tool as you can see hidden features as well which you can’t view in the UI.

Correct Installation Order for SharePoint Server 2010, Language Packs and Office Web Apps

Posted by on February 13, 2012 at 7:45 am. No comments

Here’s a great tip from SharePoint MCM Scott Jamison, Chief Architect and CEO at Jornata, around the correct order of installation for SharePoint Server, Language Packs and Office Web Apps. Yes, this stuff matters!

In order to properly install these items, you must do things in the following order:

  1. SharePoint 2010 RTM + SP1 (slipstreamed)
  2. Configure Farm using PowerShell
  3. Office Web Apps RTM + SP1 (slipstreamed)
  4. Run SharePoint Config Wizard (PSConfig) on all severs
  5. SharePoint 2010 Server Language Pack RTM + SP1 (slipstreamed)
  6. Run SharePoint Config Wizard (PSConfig) on all servers
  7. Install OCT 2011 CU (or current recommended CU)
  8. Run SharePoint Config Wizard (PSConfig) on all servers (if you get errors here, so additional note below)

Installing in any other order may cause issues and some functionality to not work properly.

Additional Note: Sometimes after installing CU’s I’ve noticed errors when trying to run the SharePoint Products Configuration Wizard (PSConfig), like in the screenshot below. In my case the PSConfig wizard was complaining about missing language packs and the CU files, which I could confirm had been installed properly and there before installing the CU. To fix this, I simply forced PSConfig through PowerShell – avoiding the GUI – and it worked like a charm!

psconfig.exe -cmd installcheck -noinstallcheck

You can find more info in a similar thread on TechNet. There's also IISRESET and rebooting your servers as potential fixes too.

Update Search Center for all Sites in a Web Application

Posted by on February 8, 2012 at 7:16 am. No comments

Recently one of my customers, like many others, decided to migrate from SharePoint 2007 to SharePoint 2010. As with most other customers they wanted to take advantage of the new social capabilities. Specifically they wanted to utilize the new Enterprise Search capabilities with filtered search results and people search integration.

Let’s say you’ve migrated content databases from 2007 to 2010, and you previously had set up your enterprise search centers to http://servername/SearchCenter. However, when you migrated these they don’t have the new and improved search center functionality in 2010. So you create a new enterprise search center at http://servername/Search. All of your site collections will still have the old search center set to be used by sub-sites, but you can mass update this with PowerShell!

Thanks to a great article by Walter Munoz, there is a simple PowerShell script you can run to fix this. You can run this script using SharePoint Management Shell for each web application you’d like to update, and it will set a new Search Center for all site collections in the web application (note I’ve added in some comments with your options for the target results page, scopes drop down, etc):

# Site Collection Search Center URL
$searchURL = "/Search/Pages"

# Site Collection Search Dropdown Mode Codes:
#
# NO NEED TO SPECIFY SEARCH RESULTS PAGE
# HideScopeDD - Do Not Show Scopes Dropdown, and default to target results page
# ShowDD_NoContextual - Show, do not include contextual scopes
# ShowDD_NoContextual_DefaultURL - Show, do not include contextual scopes, and default to 's' URL parameter
#
# NEED TO SPECIFY SEARCH RESULTS PAGE
# HideScopeDD_DefaultContextual - Do Not Show Scopes Dropdown, and default to contextual scope
# ShowDD_DefaultContextual - Show and default to contextual scope
# ShowDD - Show scopes Dropdown
# ShowDD_DefaultURL - ShowDD_DefaultURL
#
$searchDDMode = "HideScopeDD"

# Site Collection Search Results Page
$searchResultsP = ""

# Get the Web Application
$webApplication = Get-SPWebApplication http://sharepoint

# loop through the sites in the web application
foreach ($site in $webApplication.Sites)
{
      # Get the root web
      $web = $site.RootWeb
      # We want to update all sites that are not a search center
      if ($web.WebTemplate -ne "SRCHCEN")
      {
         # Site Collection Search Center
         $web.AllProperties["SRCH_ENH_FTR_URL"] = $searchURL

         # Site Collection Search Dropdown Mode
         $web.AllProperties["SRCH_SITE_DROPDOWN_MODE"] = $searchDDMode

         # Site Collection Search Results Page - UNCOMMENT NEXT LINE IF USING ONE OF THE "Need to specify search results page" SEARCH MODES ABOVE
         #$web.AllProperties["SRCH_TRAGET_RESULTS_PAGE"] = $searchResultsP

         $web.Update()

         Write-Host "Updated Search Settings on Site Collection: " $web.Url
      }
}

You can download the PowerShell script here as a .txt file, just update to a .ps1 and set variables as well as your web application URL.

On a side note, if you’re not ready to upgrade to SharePoint 2010 yet but want to take advantage of some similar functionality take a look at the MOSS Faceted Search project on CodePlex. It gives you some advanced search refinements and such to enhance the experience before pulling the trigger on a big migration. Remember, always test in a test SharePoint farm first before production!

Extract WSP from SharePoint Config Database Using PowerShell

Posted by on January 30, 2012 at 6:49 pm. No comments

Manage Farm SolutionsIn an ideal word everyone always keeps great track of their custom SharePoint solution source code, right? Wrong.

If you have great developers or you yourself take meticulous care of source code and versions you can always get to your code. Rebuilding a new WSP is simple especially if you need to make changes.

However, if TFS or other source control server blows up or your dog eats your source code you’re not totally out of luck! I just came across a great article by Kirk Evans on MSDN describing how to extract a WSP from the SharePoint Config Database, which has come in handy:

$farm = Get-SPFarm
$file = $farm.Solutions.Item("wspfilename.wsp").SolutionFile
$file.SaveAs("c:\users\James\Desktop\savetowspfilename.wsp")

It’s as simple as that. Using SharePoint Management Shell get the farm, specify the WSP to extract, then specify where you want it to go. I also found a great article describing how to export all of your solutions at the same time! If you need to go even further and reclaim your source code, Telerik has a great (and free) .Net Decompiler tool to decompile your code. I’ve heard the .Net Reflector works pretty well for that too although I haven’t used it myself.

Additionally if you’re new to deploying SharePoint solutions here are two other helpful PowerShell commands to add and deploy new SharePoint solutions (more info and options on TechNet).

Adding a New WSP

Add-SPSolution -LiteralPath <SolutionPath>

Deploying a New WSP

Install-SPSolution -Identity <SolutionName> -WebApplication <URLname>

Note you can also deploy WSP’s through Central Admin under Manage Farm Solutions in System Settings (ex- http://server:5000/_admin/Solutions.aspx). However, the only want to add new WSP files is through PowerShell. New versions also must be retracted and completely removed before adding the new version as you can’t have multiple WSP’s with the same GUID deployed to the farm.

SharePoint 2010 Balsamiq Mockup Wireframe Template

Posted by on November 15, 2011 at 12:31 pm. 5 comments

One of my favorite things to do when designing a new SharePoint 2010 branding feature is the planning phase. I know what you’re thinking, “you actually enjoy going back and forth, spinning your wheels with customer design teams who take weeks to make decisions?” Yes, I do.

Before doing any actual design work, I love to use a tool called Balsamiq Mockups (really great, friendly team over there by the way). Using this tool you can quickly and easily make wire frame mockups and review them with decision makers to get your layouts right. I’ve made a template for SharePoint 2010 – screenshot below – you can download free here .

Although it can be tedious and sometimes annoying, it really helps flush out all the bad design thoughts many people have. Believe it or not everyone is an “expert” when it comes to design and the look and feel of their corporate image. I’ve run into a few really good designers or folks with good constructive minds, but more often than not people just want to be a part of it more than actually focusing on the best option.

Anyways… to aid in the process I always recommend going through the same steps to successful design:

  1. LISTEN: Understand the customer’s needs and really understand their end goal. Remember, budget and timeline often must take priority over extra features, as much as you might want to go above and beyond.
  2. VALIDATE: Make sure the right key business decision makers have not only reviewed, but also signed off on what you’re thinking. This needs to be done every step of the way really, not just in the beginning.
  3. INITIATE: Start making layouts! Using tools like Balsamiq Mockups is really helpful here, making simple and quick wire frame designs. Balsamiq is great because it doesn’t focus on style – ignore colors, fonts, images, etc at this point – really focus on the structure. You need the foundation before you build a skyscraper, designing an application is no different.
  4. STYLE: My favorite part by far, here’s where you actually spend the time to make it look cool. Again, it’s important to validate, validate, validate every step of the way.
  5. APPROVAL: Of course you’ll need that final approval and sign off from not just the core team, but the business as well. If your main sponsor/contact hasn’t scheduled this make sure you do!
  6. PUBLISH: You’re live! Consider it closed? Nope, not yet… always remember the post-launch support and tweaks that will follow.