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. [string]$solution = Read-Host "Enter the Solution name: [e.g. MyCustomSolution.wsp]"
  3. try {
  4. Write-Verbose "Getting solution features ..."
  5. $features = @()
  6. $solution1 = Get-SPSolution -Identity $solution -ErrorAction SilentlyContinue
  7. foreach ($grp in Get-SPFeature | where {$_.SolutionID -eq $solution1.id} | Group-Object SolutionId) {
  8. foreach ($fd in $grp.Group | sort DisplayName ) {
  9. $feature = New-Object -TypeName PSObject -Property @{
  10. SolutionName = $solution1.Name
  11. SolutionId = $solution1.Id
  12. FeatureName = $fd.DisplayName
  13. FeatureId = $fd.Id
  14. FeatureScope = $fd.Scope
  15. }
  16. $features += $feature
  17. }
  18. }
  19. Write-Output $features
  20. }
  21. catch [Exception] {
  22. Write-Error $Error[0]
  23. $err = $_.Exception
  24. while ( $err.InnerException ) {
  25. $err = $err.InnerException
  26. Write-Output $err.Message
  27. }
  28. }
Complete Code
  1. $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
  2. $LogFile = ".\FeaturePackedInSolutionPatch-$LogTime.rtf"
  3. # Add SharePoint PowerShell Snapin
  4. if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
  5. Add-PSSnapin Microsoft.SharePoint.Powershell
  6. }
  7. $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
  8. Set-Location $scriptBase
  9. #Deleting any .rtf files in the scriptbase location
  10. $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
  11. if($FindRTFFile)
  12. {
  13. foreach($file in $FindRTFFile)
  14. {
  15. remove-item $file
  16. }
  17. }
  18. start-transcript $logfile
  19. $solution = ""
  20. [string]$solution = Read-Host "Enter the Solution name: [e.g. MyCustomSolution.wsp]"
  21. try {
  22. Write-Verbose "Getting solution features ..."
  23. $features = @()
  24. $solution1 = Get-SPSolution -Identity $solution -ErrorAction SilentlyContinue
  25. foreach ($grp in Get-SPFeature | where {$_.SolutionID -eq $solution1.id} | Group-Object SolutionId) {
  26. foreach ($fd in $grp.Group | sort DisplayName ) {
  27. $feature = New-Object -TypeName PSObject -Property @{
  28. SolutionName = $solution1.Name
  29. SolutionId = $solution1.Id
  30. FeatureName = $fd.DisplayName
  31. FeatureId = $fd.Id
  32. FeatureScope = $fd.Scope
  33. }
  34. $features += $feature
  35. }
  36. }
  37. Write-Output $features
  38. }
  39. catch [Exception] {
  40. Write-Error $Error[0]
  41. $err = $_.Exception
  42. while ( $err.InnerException ) {
  43. $err = $err.InnerException
  44. Write-Output $err.Message
  45. }
  46. }
  47. 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.