Actvate a Feature on all Sites for a web application
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
##########################################################
##Actvate a Feature on all Sites for a web application ###
## http://Blog.IsaacBlum.com ##
##########################################################
##########################################################
#Create function activatefeature
function activatefeature{
## Reference to SharePoint DLL
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
## Location of sharepoint STSADM utility program, You may need to change this
$stsadm = "$env:programfilesCommon FilesMicrosoft SharedWeb Server Extensions12BINSTSADM.EXE"
#Ask for WebApp Root url to enumerate
$url = Read-Host "Please enter root url of WebApplication"
#Enumerate available features in SharePoint Farm
write-host -foregroundcolor green " Below are the available features in SharePoint Farm"
&stsadm -o scanforfeatures
#Ask for Feature Name
Write-Host "Please enter feature name that will be activated at all Sites and Sub-Sites of the specified application"
$feature = Read-Host "do not add the feature.xml. ex: %featurename%"
#Returning info for use in remainder of script
$webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($url)
#List Sites Affected
write-host -foregroundcolor green " The feature will be actvated on the following Sites:"
foreach ($site in $webapp.Sites) {
# write-host $webapp.Name
foreach ($web in $site.AllWebs) {
write-host $web.URL
}}
##Actvate Feature on all Sites
foreach ($site in $webapp.Sites) {
foreach ($web in $site.AllWebs) {
$sResult = &stsadm -o activatefeature -name $feature -url $web.URL -force
if(($sResult -like "*Operation completed successfully*")){ write-host -foregroundcolor green "Feature Actvated : "$web.URL}
else {
Write-Host -ForegroundColor "red" -BackgroundColor "white" "Activate of feature '$feature' for" $web.URL "Failed! `n $sResult"
}
}
}
}
########
########
######## |