Deactivate a Feature on all Sites for a web application

Posted by Isaac Blum 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
57
58
###############################################################################################################
##Deactivate a Feature on all Sites for a web application ###
## http://Blog.IsaacBlum.com ##
###############################################################################################################
###############################################################################################################
 
 
 
#Create function deactivatefeature
function deactivatefeature{
 
## 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:programfiles\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.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 deactivated at all Sites and Sub-Sites of the specified application"
$feature = Read-Host "do not add the \feature.xml. ex: NewsGator.SocialSites.SiteSkin"
 
#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 deactivated 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 deactivatefeature -name $feature -url $web.URL -force
		if(($sResult -like "*Operation completed successfully*")){ write-host -foregroundcolor green "Feature Deactivated : "$web.URL}
   		else {
      			Write-Host -ForegroundColor "red" -BackgroundColor "white" "Deactivate of feature '$feature' for" $web.URL "Failed! `n $sResult"
	}
    }
	}
 
}
 
 
 
 
###############################################################################################################
###############################################################################################################
###############################################################################################################
  • Share/Bookmark

Leave a Reply

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

  • Archives

  • Pages

  • Tags

  • More

Get Adobe Flash playerPlugin by wpburn.com wordpress themes