GetFeatureAndDependencies – A SharePoint PowerShell Function

As stated in my previous post, GetFeatureDefinition – A SharePoint PowerShell Function, I have been working on deploying a solution that contained multiple features which lead me down the road of feature activation dependencies. My current client’s hosting environment has me looking to see just what I can pull off with hidden features and cross-scope dependencies. In searching out any best practices around solution and feature packaging Scott Hillier suggested that I dig into the MOSS publishing features to look at how they relied on Activation Dependencies. I just happened to be reading AC’s Professional WCM book, SharePoint 2007 Web Content Management Development, where Andrew just happens to be discussing the publishing features.

So what I really wanted to do was to view some key information about a feature and it’s dependencies, for a given feature show me it’s dependency to include name, id, scope and hidden property If you have not tried to do this – well it is a time-consuming process when you must wade through the feature directory matching up feature activation ids to features.

In my previous life , lets call it BPS (Before PowerShell), I like many developers would have opened up Visual Studio, started a new console project to created a simple application that would dump the features to the screen. A typical one-shot app. But now APS (After PowerShell) I took a few minutes and created a new SharePoint PowerShell function named GetFeatureAndActivationDependencies which outputs to the screen key properties of the feature and any activation dependencies.

So a little housekeeping before the script. First this script relies on the GetFeatureDefintion function in my last post, GetFeatureDefinition – A SharePoint PowerShell Function. Make sure you add this function to your PowerShell host, either in the host itself or via a profile. Next, both GetFeatureDefintion and GetFeatureDefintionAndDependencies must run in a PowerShell host on a WSS 3 or MOSS 2007 server. Finally as stated in all my PowerShell and SharePoint post you must load the SharePoint assembly in the PowerShell environment before you use these functions. To include the SharePoint assembly in the PowerShell environment simply execute the following command in PowerShell:

[Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

PowerShell will respond with information about the newly loaded assembly.

So here is the function. It must be run on a WSS 3 or MOSS server with PowerShell

function GetFeatureAndDependencies
Param([String] $FeatureId)

getFeatureDefinition $FeatureId | sort-object{$_.DisplayName} |
“Feature Definition`n———————————————————–“
$_ | format-table DisplayName, Id, Scope, Hidden -AutoSize

$dep = $_.ActivationDependencies | foreach-object{getFeatureDefinition $_.FeatureId} | FT DisplayName, Id, Scope, Hidden -AutoSize
if($dep -ne $null)
“Activation Dependencies`n———————————————————–“
{“No Dependencies”}

Once the function has been defined in your PowerShell session try the following commands:


Ok that is a little messy, it will dump every Feature Definition along with any activation dependencies. This next command is “real-world” example. All I have been provided is a Feature Definition id..And to make it more real, I don’t know which feature maps to this ID.

GetFeatureAndDependencies F6924D36-2FA8-4f0b-B16D-06B7250180FA

To close this post, this is an example of a PowerShell script that provides a formatted output to the screen for a report-like view. This script really was not intended to be used as input into another command. The script does not output a clean set of objects.


  1. Mirrored Blogs 07/16/2008
  2. Bob Mixon 08/21/2008

Leave a Reply