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:
- $solution = ""
-
- [string]$solution = Read-Host "Enter the Solution name: [e.g. MyCustomSolution.wsp]"
-
- try {
- Write-Verbose "Getting solution features ..."
-
- $features = @()
-
- $solution1 = Get-SPSolution -Identity $solution -ErrorAction SilentlyContinue
-
- foreach ($grp in Get-SPFeature | where {$_.SolutionID -eq $solution1.id} | Group-Object SolutionId) {
- foreach ($fd in $grp.Group | sort DisplayName ) {
- $feature = New-Object -TypeName PSObject -Property @{
- SolutionName = $solution1.Name
- SolutionId = $solution1.Id
- FeatureName = $fd.DisplayName
- FeatureId = $fd.Id
- FeatureScope = $fd.Scope
- }
- $features += $feature
- }
- }
- Write-Output $features
-
- }
- catch [Exception] {
- Write-Error $Error[0]
- $err = $_.Exception
- while ( $err.InnerException ) {
- $err = $err.InnerException
- Write-Output $err.Message
- }
- }
Complete Code
- $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
- $LogFile = ".\FeaturePackedInSolutionPatch-$LogTime.rtf"
-
- # Add SharePoint PowerShell Snapin
-
-
- if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
- Add-PSSnapin Microsoft.SharePoint.Powershell
- }
-
- $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
- Set-Location $scriptBase
-
-
- #Deleting any .rtf files in the scriptbase location
- $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
- if($FindRTFFile)
- {
- foreach($file in $FindRTFFile)
- {
- remove-item $file
- }
- }
-
-
- start-transcript $logfile
-
-
- $solution = ""
-
- [string]$solution = Read-Host "Enter the Solution name: [e.g. MyCustomSolution.wsp]"
-
- try {
- Write-Verbose "Getting solution features ..."
-
- $features = @()
-
- $solution1 = Get-SPSolution -Identity $solution -ErrorAction SilentlyContinue
-
- foreach ($grp in Get-SPFeature | where {$_.SolutionID -eq $solution1.id} | Group-Object SolutionId) {
- foreach ($fd in $grp.Group | sort DisplayName ) {
- $feature = New-Object -TypeName PSObject -Property @{
- SolutionName = $solution1.Name
- SolutionId = $solution1.Id
- FeatureName = $fd.DisplayName
- FeatureId = $fd.Id
- FeatureScope = $fd.Scope
- }
- $features += $feature
- }
- }
- Write-Output $features
-
- }
- catch [Exception] {
- Write-Error $Error[0]
- $err = $_.Exception
- while ( $err.InnerException ) {
- $err = $err.InnerException
- Write-Output $err.Message
- }
- }
-
- Stop-transcript
Execution procedure
- Download and copy the script to the SharePoint server.
- Launch the SharePoint management console.
- 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.