Monday, December 5, 2011

How To Activate and Deactivate Features Using PowerShell in SharePoint 2010

In SharePoint 2007 to activate a feature from the command line you might have used a statement like the one below. I’ll use the Reporting feature on my server named sp2010 as an example. The value specified in the name parameter refers to the actual folder name of the feature that is in your SharePoint Root folder (14 hive).

stsadm.exe –o activatefeature –name Reporting –url http://sp2010

To get started with PowerShell, run the SharePoint 2010 Management Console located in your Microsoft SharePoint 2010 Products folder on your start menu. This automatically loads the Microsoft.SharePoint.PowerShell snapin so that we can execute SharePoint commands. You might have noticed earlier that I said we will talk about enabling and disabling features. The words enable and disable are key here because PowerShell uses those verbs to activate and deactivate features. To issue the same command above but with PowerShell, we use the Enable-SPFeature command. The rest of the syntax is pretty similar as you can see below. Just use –Identity to specify the name of the feature. You can even pass the –Force command like you could with stsadm.exe.

Enable-SPFeature –Identity Reporting –url http://sp2010

If your command worked successfully, you will see nothing and just get a blank prompt back.


If you would like to get some feedback from the command, you can have it return the SPFeature object back to you by specifying the –PassThru parameter.



We can confirm that the feature did in fact activate successfully using the SharePoint UI.


Can we confirm that the feature is enabled with PowerShell? Yes, we can by using Get-SPFeature. Now this cmdlet behaves differently depending upon the parameters passed through it. For example, if you type the following, it lists every feature on the SharePoint farm along with its Id and Scope.

Get-SPFeature

However, if you want to know which features are enabled, you can pass it a URL for a given scope (i.e.: –Web, –Site, –WebApplication, and –Farm). So to get a list of all Site Collection scoped features, we would use the –Site parameter.

Get-SPFeature –Site http://sp2010


You can still specify a specific feature or even use Where-Object to query the list as well.

Get-SPFeature –Identity Reporting –Site http://sp2010

If you get something like you see in the screenshot above, you know the feature has been activated. When the feature hasn’t been activated, you will get a lovely red error message.

The Enable-SPFeature command can also take a Pipe Bind from Get-SPFeature. This means that you could even activate multiple features at once this way. I’ll include an example of this in the future.

At some point, you will want to disable that feature you activated. As you probably guessed, the cmdlet you want is Disable-SPFeature. You use the same parameters that you use with Enable-SPFeature. When you execute the command, it prompts for confirmation as you can see in the screenshot.

Disable-SPFeature –Identity Reporting –url http://sp2010


If you want to disable confirmation, you can pass the –confirm:$false parameter.

Disable-SPFeature –Identity Reporting –url http://sp2010 –Confirm:$false


Setting the confirm parameter eliminates the confirmation prompt and you can use it with other PowerShell cmdlets as well. That is all that is involved in activating and deactivating features with PowerShell. It’s pretty easy. Hopefully, you can incorporate these commands in your deployment scripts.

Note: Remember quotes if the feature folder contains spaces. Alternatively, you can specify the feature ID 

No comments:

Post a Comment