Finding Features Packed in SharePoint Solution

Features

A Feature is a container of various defined extensions for SharePoint Server 2010 and is composed of a set of XML files that are deployed to front-end Web servers and application servers. You can deploy a Feature as part of a solution package and you can individually activate a Feature in SharePoint Server sites.

Features are packages of functionality that you can activate and deactivate in a SharePoint Farm. They have the following four possible scopes.

Farm: A Farm level feature, as the name suggests, is something that affects the entire Farm.

Web Application: A web application feature can be activated so that it only affects a single web application and a typical example is a feature that modifies the web.config file.

Site: A site scoped feature can be activated so that it only affects a site collection, an example being the deployment of a master page to the master pages catalogue.

Web: Finally, a web scoped feature can be activated for a single site, for instance setting the default master page for that site.

Features make it easier to activate or deactivate functionality in the course of a deployment and administrators can easily transform the template or definition of a site by turning on or turning off a specific Feature in the user interface.

Feature packed in SP solution

The following piece of code finds the feature packed in given solution:
  1. $solution = ""  
  2.   
  3. [string]$solution = Read-Host "Enter the Solution name: [e.g. MyCustomSolution.wsp]"  
  4.   
  5. try {  
  6.     Write-Verbose "Getting solution features ..."  
  7.   
  8.     $features = @()  
  9.   
  10.     $solution1 = Get-SPSolution -Identity $solution -ErrorAction SilentlyContinue  
  11.   
  12.     foreach ($grp in Get-SPFeature | where {$_.SolutionID -eq $solution1.id} | Group-Object SolutionId) {  
  13.     foreach ($fd in $grp.Group | sort DisplayName ) {  
  14.         $feature = New-Object -TypeName PSObject -Property @{  
  15.         SolutionName = $solution1.Name  
  16.         SolutionId = $solution1.Id  
  17.         FeatureName = $fd.DisplayName  
  18.         FeatureId = $fd.Id  
  19.         FeatureScope = $fd.Scope  
  20.         }  
  21.         $features += $feature  
  22.         }  
  23.         }  
  24.         Write-Output $features  
  25.   
  26.       }  
  27. catch [Exception] {  
  28.     Write-Error $Error[0]  
  29.     $err = $_.Exception  
  30.     while ( $err.InnerException ) {  
  31.         $err = $err.InnerException  
  32.         Write-Output $err.Message  
  33.         }  
  34.       }  
Complete Code
  1. $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm  
  2. $LogFile = ".\FeaturePackedInSolutionPatch-$LogTime.rtf"  
  3.  
  4. # Add SharePoint PowerShell Snapin  
  5.   
  6.   
  7. if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {  
  8.     Add-PSSnapin Microsoft.SharePoint.Powershell  
  9. }  
  10.   
  11. $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent  
  12. Set-Location $scriptBase  
  13.  
  14.  
  15. #Deleting any .rtf files in the scriptbase location  
  16. $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf  
  17. if($FindRTFFile)  
  18. {  
  19.     foreach($file in $FindRTFFile)  
  20.         {  
  21.             remove-item $file  
  22.         }  
  23. }  
  24.   
  25.   
  26. start-transcript $logfile  
  27.   
  28.   
  29. $solution = ""  
  30.   
  31. [string]$solution = Read-Host "Enter the Solution name: [e.g. MyCustomSolution.wsp]"  
  32.   
  33. try {  
  34.     Write-Verbose "Getting solution features ..."  
  35.   
  36.     $features = @()  
  37.   
  38.     $solution1 = Get-SPSolution -Identity $solution -ErrorAction SilentlyContinue  
  39.   
  40.     foreach ($grp in Get-SPFeature | where {$_.SolutionID -eq $solution1.id} | Group-Object SolutionId) {  
  41.     foreach ($fd in $grp.Group | sort DisplayName ) {  
  42.         $feature = New-Object -TypeName PSObject -Property @{  
  43.         SolutionName = $solution1.Name  
  44.         SolutionId = $solution1.Id  
  45.         FeatureName = $fd.DisplayName  
  46.         FeatureId = $fd.Id  
  47.         FeatureScope = $fd.Scope  
  48.         }  
  49.         $features += $feature  
  50.         }  
  51.         }  
  52.         Write-Output $features  
  53.   
  54.       }  
  55. catch [Exception] {  
  56.     Write-Error $Error[0]  
  57.     $err = $_.Exception  
  58.     while ( $err.InnerException ) {  
  59.         $err = $err.InnerException  
  60.         Write-Output $err.Message  
  61.         }  
  62.       }  
  63.   
  64. Stop-transcript  
Execution procedure
  1. Download and copy the script to the SharePoint server.
  2. Launch the SharePoint management console.
  3. Navigate to the script path and execute it.


Enter the solution name.

Conclusion

Thus this article outlines how to find the features packed in the given SharePoint 2010 solution using a PowerShell script.

Up Next
    Ebook Download
    View all
    Learn
    View all