none
how to get all site features and custom features from sharepoint sitecollection?

    Question

  • how to get all site features and custom features  from sharepoint sitecollection?

    i have a site with multiple site features and each site having multible features.

    how can i get all those from sharepoint sitecollection url?

     help me programatically using server object model...?

    Wednesday, September 12, 2012 3:00 PM

Answers

  • To do you should use a powershell script, I made this one to list all of them :

    $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local 
    $websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]} 
    $webapps = @() 
    
    $file= "\\public\rboussion\PS_script\SharepointList.csv"
    out-file -Encoding UTF8 -filepath $file -inputObject "WebApplication, Site Collection, Name, Feature Id, Solution ID"
    
    write-host "Processing start ..." 
    
    
    foreach ($websvc in $websvcs) {		
        foreach ($webapp in $websvc.WebApplications) { 
    		add-content ($webapp.Name) -path $file		
    		if($webapp.Name -eq "SharePoint - portal.rboussion.fr"){
    			foreach ($site in $webapp.Sites){ 				
    					add-content (","+$site.URL) -path $file
    					$features = Get-SPFeature -Site $site.URL 
    						#desc=Get-SPFeature -Site $site.URL | select getdescription;
    						foreach ($feature in $features){							
    							add-content (",,"+$feature.DisplayName+","+$feature.Id+","+$feature.SolutionId) -path $file		
    						}
    				}		
    			} 
        }
    }
    write-host "End process"
    write-host "This file has been created : " $file
    write-host ""
    


    Régis BOUSSION

    Wednesday, September 12, 2012 3:07 PM
  • And this is the object model way to query all features in a specific site collection: 

    SPSite site = new SPSite("http://SiteURL");
    
    SPFeatureQueryResultCollection features = 
    		    site.QueryFeatures(SPFeatureScope.Site, true);
    		
    IEnumerator<SPFeature> featureEnumerator = features.GetEnumerator();
    while (featureEnumerator.MoveNext())
    {
    SPFeature feature = featureEnumerator.Current;
    Console.WriteLine("Name: "+ feature.Name);
    }
    

    Wednesday, September 12, 2012 4:48 PM

All replies

  • To do you should use a powershell script, I made this one to list all of them :

    $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local 
    $websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]} 
    $webapps = @() 
    
    $file= "\\public\rboussion\PS_script\SharepointList.csv"
    out-file -Encoding UTF8 -filepath $file -inputObject "WebApplication, Site Collection, Name, Feature Id, Solution ID"
    
    write-host "Processing start ..." 
    
    
    foreach ($websvc in $websvcs) {		
        foreach ($webapp in $websvc.WebApplications) { 
    		add-content ($webapp.Name) -path $file		
    		if($webapp.Name -eq "SharePoint - portal.rboussion.fr"){
    			foreach ($site in $webapp.Sites){ 				
    					add-content (","+$site.URL) -path $file
    					$features = Get-SPFeature -Site $site.URL 
    						#desc=Get-SPFeature -Site $site.URL | select getdescription;
    						foreach ($feature in $features){							
    							add-content (",,"+$feature.DisplayName+","+$feature.Id+","+$feature.SolutionId) -path $file		
    						}
    				}		
    			} 
        }
    }
    write-host "End process"
    write-host "This file has been created : " $file
    write-host ""
    


    Régis BOUSSION

    Wednesday, September 12, 2012 3:07 PM
  • And this is the object model way to query all features in a specific site collection: 

    SPSite site = new SPSite("http://SiteURL");
    
    SPFeatureQueryResultCollection features = 
    		    site.QueryFeatures(SPFeatureScope.Site, true);
    		
    IEnumerator<SPFeature> featureEnumerator = features.GetEnumerator();
    while (featureEnumerator.MoveNext())
    {
    SPFeature feature = featureEnumerator.Current;
    Console.WriteLine("Name: "+ feature.Name);
    }
    

    Wednesday, September 12, 2012 4:48 PM