SharePoint Tech Blog

29/07/2010

Enumerate SharePoint features using Powershell

Filed under: PowerShell, SharePoint — Tags: , — kctnpblog @ 8:42 pm

This code requires the SharePoint Powershell Profile to be loaded.

To execute the code, provide the site url as a command line parameter.
e.g. powershell .\listfeatures.ps1 http://site

The output lists the features on the web application, site collection and web.


function writefeature($featureobj) {
$featuredef=$featureobj.DefinitionId;
$feature=$farm.FeatureDefinitions[$featuredef];
"{0,-40} {1,-50} {2,-40}" -f $feature.Id , $feature.DisplayName , $feature.Scope;
}

function setwindowsize() {
$pshost = get-host
$pswindow = $pshost.ui.rawui

$newsize = $pswindow.buffersize
$newsize.height = 3000
$newsize.width = 150
$pswindow.buffersize = $newsize

}

#Sets the size of the window to display well formatted output
setwindowsize

#Get command line parameter for url
$url=$args[0];

$farm = Get-SPFarm;

"Web application features"
$webapp = Get-SPWebApp $url;
$webapp.Features | ForEach-Object {
writefeature $_;
}

""
"Site collection features"
$spsite=Get-SPSite -url $url;
$spsite.Features | ForEach-Object {
writefeature $_;
}
$spsite.Dispose();

""
"Web features"
$spweb=Get-SPWeb -url $url;
$spweb.Features | ForEach-Object {
writefeature $_;
}
$spweb.Dispose();

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: