mandag den 17. december 2012

How to get feature scope using powershell

As i promissed in last post, here is a quick example for a easy way to get the feature scope, when you want to enable a Sharepoint feature.

I added two small functions that can activate a feature based its scope. this way you dont have to specify the feature scope in the script and this way you only need one function for all your features. This function will work fine with my lates post on how to specify all the features in an xml file.

This function takes two parameters: The Identety of the feature, and the URL for a given site. If the url is empty it is set to $null.

function ActivateFeature
{    param(
         $Url = $null
if ($installedFeature = checkFeatureInstalledAndScope -FeatureID $Identity)

{    switch ($installedFeature.Scope)
       $feature = (Get-SPFeature -Identity $Identity -Farm
       -erroraction silentlycontinue)

       $feature = (Get-SPFeature -Identity $Identity -WebApplication $Url
       -erroraction silentlycontinue)
        $feature = (Get-SPFeature -Identity $Identity -Site $Url
        -erroraction silentlycontinue)
        $feature = (Get-SPFeature -Identity $Identity -Web $Url
        -erroraction silentlycontinue)
Write-Host "Enabling feature: " $installedFeature.Id "..." -NoNewline

if ($installedFeature.scope -eq "Farm")
   Enable-SPFeature -Identity

   Enable-SPFeature -Identity
$Identity -Url $Url

Write-Host -ForegroundColor Green "DONE"

function checkFeatureInstalledAndScope

  if ($feature = (get-spfarm).FeatureDefinitions | ?{$_.Id -eq $FeatureID})
    return $feature

  return $null

onsdag den 12. december 2012

Activate features using XML file

I have worked with a smal powershell script that activate a lot of features specified in a XML file.

I was strucling with a script that had all features hardcoded in the script, and I thought to myself, that there should be a better way to du this! More stuctured! Easyer to maintain!

The way to activate a feature using powershell is well known.
 - Enable-SPFeature -Identity "Identity"
Look here for more information on the Enable-SPFeature command

So how can we then make this more structured. Well my idear is to use a xml file to hold all the features that need enables. his also makes the maitanece more simple.
For this scrip I use true/false to activate features in the xml file.

This is an example on the xml structure I use.
<?xml version="1.0" encoding="utf-8"?>
   <Features Name="Farm">

      <Feature Enable="true" Scope="Farm" Identity=""></Feature>

So how to import the xml file in the script.
$dp0 = the location of the script.

$featureXMLFile = $dp0 + "\xx.xml"
[xml]$FeatureConfig = [xml](Get-Content $featureXMLFile)

Using this xml file in a scrip to find the features that need activating.

$featuresEnabled = $FeatureConfig.SelectNodes
#Finding features set to be enabled (Enable="true")
("DeploymentConfig/Features/Feature") | where {$_.Enable -ieq "true"}

if ($featuresEnabled)
  Write-Host -ForegroundColor Green "--------------------------"
  Write-Host -ForegroundColor Green "- Activating Features"

  #Farm scoped features
  $farmFeatures = $featuresEnabled | where {$_.Scope -eq 'Farm'}
  if ($farmFeatures)
    Write-Host -ForegroundColor Green " - Enabling Farm scoped feature:"
    foreach ($feature in $farmFeatures)
$FeatureUID = $feature.Identity
Enable-SPFeature -Identity $FeatureUID
    Write-Warning "No Farm features to activate"


This little script only handles farm features. To use it for weballication/sitecollection features you need to add a webapplication/site to the command.
Enable-SPFeature -Identity $FeatureUID -Url $Url

To make this possible you need to create a new section in the xml file that specify the features that need activation. in this example I use webapplication.
<Features Name="WebApplication">
  <Feature Enable="false" Scope="WebApp" Site="" Identity=""></Feature>

The code should look like this.
$webappFeatures = $featuresEnabled | where {$_.Scope -eq 'WebApp'}
if ($webappFeatures )
  Write-Host -ForegroundColor Green " - Enabling webapplication scoped feature:"
  foreach ($feature in $webappFeatures )

    $FeatureUID = $feature.Identity

    $Url = $feature.Site
    Enable-SPFeature -Identity $FeatureUID -Url $Url 


You can of course build this into a larger script, and I will in a later post discripe how to find out if a feature is farm, webapp, site or web.

Have fun with powershell.

fredag den 7. september 2012

Sharepoint 2010 SPUpdatedConcurrencyException Fix

Problems when installing the June_CU_2011 (KB) for SharePoint Server.

After installing the CU, and running the online command <psconfig –cmd upgrade –inplace b2b –wait> to update the second server in the farm. You may get this error just after step 2:


An exception of type Microsoft.SharePoint.Administration.SPUpdatedConcurrencyException was thrown. Additional exception information: An update conflict has occurred, and you must re-try this action. The object SPUpgradeSession Name=Upgrade -20110924-194525-15 was updated by DOMAIN\ACCOUNT, in the PSCONFIG (7240) process, on machine SERVER. View the tracing log for more information about the conflict.

Total number of configuration settings run: 3

Total number of successful configuration settings: 2

Total number of unsuccessful configuration settings: 1

Successfully stopped the configuration of SharePoint Products.

Configuration of SharePoint Products failed. Configuration must be performed before you use SharePoint Products. For further details, see the diagnostic log located at [LOCATION OF LOG] and the application event log.

To Resolve this in a fast an easy way:
  1. stsadm -o setproperty -pn command-line-upgrade-running -pv No
  2. IISReset
  3. Restart the Windows SharePoint Timer
  4. psconfig –cmd upgrade –inplace b2b –wait –force
This PSConfig make a check to see if a installation is allready running. And if this sitting is set to yes the PSConfig throw an exeption.
To fix this, you can set the "command-line-upgrade-running" property to "No" and viola, the installation can finish.

To learn more see:

How to Make PDF icons visible

Just a short guide to make PDF icons visible in SharePoint 2010.

I found this article on the Net and found that it is usefull if you want icons in your search results. This article is using PDF iFilter.