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();