Actvate a Feature on all Sites for a web application

Posted by IsaacBlum at 31 December 2009

Category: Uncategorized

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"
	}
    }
	}
}
 
 
 
########
########
########

Leave a Reply

Leave a Reply
  • (required)
  • (required) (will not be published)

  • Archives

  • Tags

  • Subscribe
  • Pages

  • More

  • Disclaimer…

    This is my personal weblog. The opinions expressed herein are my own and are not representative of any 3rd party influence. The owner of this blog reserves the right to edit or delete any comments submitted to this blog without notice if they are deemed to be spam, offensive or otherwise inappropriate. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.


    Lastly, I do my best to document my sources if the article is not of my own creation. If I have missed or forgotten to source your work. I would love feedback via the comments section. Thank you.

DreamHost promos
SiteLock