What is a SharePoint Feature?
A feature is a major component in the development and deployment of the solution in the SharePoint environment and is composed as an XML file. Every functionality will have the feature.xml file which contains the application GUID, Scope, and related information.
Based on the scope level, SharePoint will determine where the solution should work either in the web application level, site collection level, or at the subsite level. Here, we will see how to check the OOTB SharePoint Features using PowerShell console.
First, let us add the Microsoft SharePoint PowerShell snap-in to the PowerShell console by using the below line of code.
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Once we've added the Snap-in, now, PowerShell can populate the SharePoint Cmdlets. To get the feature details in web application level, use the below line.
Get-SPFeature -WebApplication https://sharepointserver:portnumber
You will get the list of features available in the web application level with GUID and Scope level, then use the same cmd to check the site collection level features for the site collection.
Get-SPFeature -Site https://sharepointserver:portnumber/sitecollection
And for subsite, type -
Get-SPFeature -Web https://sharepiontserver:portnumber/sitecollection/subsite
Now, we will check if any particular feature is activated on the site collection level or not using name or GUID. Let’s take the media web part feature and the GUID is 5b79b49a-2da6-4161-95bd-7375c1995ef9
Using DisplayName
Get-SPFeature –Site https://sharepointserver:portnumber/sitecollection | Where-Object {$_.DisplayName -eq "MediaWebPart"}
Using GUID
Get-SPFeature -Site https://sharepointserver:portnumber/sitecollection| Where-Object {$_.Id -eq "5b79b49a-2da6-4161-95bd-7375c1995ef9 "}
If the feature is activated at the site collection level, then you will get a result as a feature name with GUID. If the feature doesn’t activate, you will get an error like “Object reference not set to an instance of an object”.
OK. Now, we will expand this cmdlet as a script to check aif ny particular feature is activated or not in all the site collections in a web application.
- <! – Script Starts -->
- Add-PSSnapin "Microsoft.SharePoint.PowerShell" $web = Get-SPWebApplication -Identity "https://sharepointserver:portnumber"
- Foreach($site in $web.Sites)
- {
- $feature = Get-SPFeature -Site $site | Where-Object {$_.DisplayName -eq "MediaWebPart"
- }
- if($feature -ne $null)
- {
- Write-Host $site.RootWeb.Url " - Activated"
- }
- if($feature -eq $null)
- {
- Write-Host $site.RootWeb.Url " - Deavtivated"
- }
- }
- <! —script Ends -->