01.
[system.reflection.assembly]::LoadWithPartialName(
"Microsoft.SharePoint"
)
02.
03.
function
ListFeaturesAux($header, $features, $obj, $boolremove)
04.
{
05.
foreach ($feature
in
$features)
06.
07.
if
( $feature.Definition -eq $NULL)
08.
09.
write-host
"Missing feature definition (feature id:"
$feature.DefinitionId
"), Scope: "
$header
10.
( $boolremove -eq $TRUE)
11.
12.
try
13.
$obj.Features.Remove($feature.DefinitionId,$
true
14.
"Feature "
" has been removed."
15.
16.
}
17.
catch
18.
"An error occured while removing feature:"
19.
20.
21.
22.
23.
ELSE
24.
25.
#write-host $feature.Parent " " $feature.Definition
26.
27.
28.
29.
30.
ListFeaturesWeb($web, $boolremove)
31.
32.
33.
$header =
"Web: "
+ $web.Url
34.
ListFeaturesAux $header $web.Features $web $boolremove
35.
36.
foreach( $subweb
$web.Webs)
37.
38.
ListFeaturesWeb $subweb $boolremove
39.
40.
41.
42.
43.
44.
ListFeaturesSite($site, $boolremove)
45.
46.
"Site collection: "
+ $site.Url
47.
ListFeaturesAux $header $site.Features $site $boolremove
48.
49.
50.
51.
52.
list-orphaned-Features ($url,$boolremove)
53.
54.
55.
56.
$webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($url)
57.
write-host $webapp.displayname
58.
59.
foreach($Site
$webapp.Sites )
60.
61.
ListFeaturesSite $Site $boolremove
62.
ListFeaturesWeb $Site.RootWeb $boolremove
63.
64.
65.
66.
#change parameter boolremove from $FALSE to $TRUE to remove the feature
67.
list-orphaned-Features
"http://sp2007"
$FALSE
Richard Mueller edited Revision 3. Comment: Modified title casing, removed tag "SharePoint 2007 (en-US)", added tag "Has Code"