Saturday, 19 May 2012

SharePoint Administration: identifying the farm solution that supplied a feature

Several times I’ve been asked how to identify what features are supplied by which solutions that are installed on a farm.  Usually this comes up in combination with inventorying the features actually being used on a site in preparation for a migration to a new farm or upgrade to a new version.  Luckily, SharePoint does track enough information to match this up.  The SPFeatureDefinition object has a SolutionId property, which corresponds to the Id property of a SPSolution object (from SPFarm.Solutions).  Putting that together is just a matter of some PowerShell (tested on SP 2010, *should* work on SP 2007, but untested):

$a = [System.Reflection.Assembly]::LoadWithPartialName("System.Xml");

$a = [System.Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq");

$a = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");

$a = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration");



$farm = [microsoft.sharepoint.administration.spfarm]::Local

$solutions = @{};

$farm.Solutions | %{ $solutions[[Guid]$_.Id] = $_ };

$features = @(

    $farm.FeatureDefinitions | 

    ?{ $_.SolutionId -ne [Guid]::empty} |

    %{

        $solution = $solutions[[Guid]$_.SolutionId];

        $solutionName = $solution.Name;

        if($solutionName -eq $null)

        {

            $solutionName = ("Unknown solution {0}" -f $_.SolutionId)

        }

        new-object PSObject -Property @{

            Definition = $_;

            Id = $_.Id;

            DisplayName = $_.DisplayName;

            Solution = $solution;

            SolutionName = $solutionName;

        }

    }

);

$features | format-table Id,DisplayName,SolutionName;

And that’s it.  As-written, it will output the Id, Name, and Solution name for each feature SharePoint has marked as coming from a solution (including some of the OOTB features that really didn’t come from a WSP).  Modify the last line to output to a file, or join it to your other script that collects the list of activated features for a site/web, and you’re in business.