Activating and Deactivating Features with PowerShell in SharePoint 2010

Posted Tuesday, January 4, 2011 3:53 PM by CoreyRoth

I was looking at the analytics of the site the other day and I noticed that my post, Adding and Deploying Solutions with PowerShell, currently has the most traffic on the site.  I had always intended to write a follow up post on this, so here it is.  Today I’m going to talk about how to enable and disable features using PowerShell.  It’s great that you know how to deploy solutions now with PowerShell, but now you want to activate your features.

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 Reportingurl 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.

PowerShellEnableSPFeatureNoOutput

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.

PowerShellEnableSPFeaturePassThru

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

PowerShellReportingFeatureEnabledUI

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

PowerShellGetSPFeatureSite

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

PowerShellGetSPFeatureSiteSpecific

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.

PowerShellGetSPFeatureSiteSpecificNotEnabled

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

PowerShellDisableSPFeatureWithConfirmation

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

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

PowerShellDisableSPFeatureNoConfirmation

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.

Comments

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Thursday, May 5, 2011 4:41 AM by Thomas Møller Jørgensen

Just a quick note: Remember quotes if the feature folder contains spaces. Alternatively, you can specify the feature ID.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Thursday, May 5, 2011 11:15 PM by Venkatesh R

Thanks for explanation with screenshots.

# My resource to learn on 70-573 « martinbodocky

Wednesday, May 11, 2011 5:23 AM by My resource to learn on 70-573 « martinbodocky

Pingback from  My resource to learn on 70-573   « martinbodocky

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Tuesday, October 4, 2011 1:13 PM by Neville A. Williams

I am trying to move a site from a 2007 SharePoint in Domain A to a 2010 SharePoint in Domain B using STSADM. Microsoft says it can be done. But I am noticing a different behavior in 2010. How can I make this work?

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Monday, October 17, 2011 9:35 PM by CoreyRoth

@Neville I'm afraid I haven't tried that particular scenario.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Wednesday, November 23, 2011 2:04 PM by Rick

Thanks for the info...clear and concise.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Wednesday, November 23, 2011 2:05 PM by Rick

Thanks for the info...clear and concise.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Wednesday, December 14, 2011 7:32 AM by Ish

This DOES NOT work if the feature has a feature receiver for activation.  The code does NOT run.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Wednesday, December 28, 2011 2:50 AM by Kourosh

Hi,

I have a feature which as a event reciever , I have added it to my WebTemplate's Onet.xml when you create a subweb by PowerShell the event reciever will trigged, now I want to debug it when i execute the powershell script, how can i to do it? thanks.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Thursday, January 5, 2012 3:48 PM by CoreyRoth

@Kourosh Try this technique that I use with cmdlets.  It should work.  www.dotnetmafia.com/.../how-to-debug-a-powershell-cmdlet.aspx

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Thursday, January 5, 2012 4:04 PM by CoreyRoth

@Ish it should.  Make sure that your event receiver is not in the same assembly (or solution package as the feature you are activating).  It also need to be installed to the GAC if you are activating with PowerShell (although it probably already is).  Lastly, make sure the account you are using is in the Get-SPShellAdmin group.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Wednesday, January 18, 2012 4:18 AM by Amir Khan

Hi Cory

Thanks for the write up.

We have noticed a very strange behaviour when activating the PublishingSite site collection feature via the gui and via powershell and I'm wondering if you have any ideas or thoughts on it.

What we notice in all of our sharepoint farms that when we manually or via script activate the Publishing Site feature and waited it takes about 2-3 minutes before it shows that its activated.

Thiis is too long for us so we've been trying to understand where the bottleneck is. Lots of perf testing but nothing clear as of yet.

Then, I noticed something very strange and confusion!

If I activate the Publishing Site feature via the gui, wait 3 seconds, refresh the page and then click the activate button again the feature is activated in less then 10 seconds!

I proceed to activate the publishing web feature as well which is done instantly and everything is in place.

Can you explain this? Why does it go blazing fast after a refresh?

I would be very grateful if you had any thoughts to share.

Thank you

Amir

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Thursday, January 19, 2012 3:33 AM by sravan

This is a good post. we can easily understand how to enable and disable features using powershell command

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Wednesday, January 25, 2012 4:31 AM by Nilesh

Cannot find an SPSite object with Id or Url: customer/.../default.aspx.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Monday, February 6, 2012 10:36 AM by tstojecki

For sandboxed solutions you will need to add the Sandboxed switch, e.g.: get-spfeature -Sandboxed -Site $siteUrl.

Get-SPFeature doesn't list out the sandboxed features without it.

# Trials and Tribulations: Migrating My Demos Site to Office365 – Part Two » Marc D Anderson's Blog

Pingback from  Trials and Tribulations: Migrating My Demos Site to Office365 – Part Two » Marc D Anderson's Blog

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Monday, February 6, 2012 11:54 PM by CoreyRoth

@Nilesh make sure your account has proper permissions.  It should also be in the Shell Admin group visible by running Get-SPShellAdmin.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Tuesday, February 7, 2012 12:11 AM by CoreyRoth

@Amir  I haven't noticed it, but I'll give it a try when I have a chance and see if I can reproduce it.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Monday, March 26, 2012 11:47 PM by TerryB

@Corey, You made a fairly significant statement in "Make sure that your event receiver is not in the same assembly (or solution package as the feature you are activating)."

We are having endless pain deploying a solution and activating features via powershell. The last thing we have not tried is putting the feature receivers into a separate solution. I was hoping you could expand on the idea, or point to any documentation that supports the practise.

Thanks Terry

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Monday, April 2, 2012 11:00 PM by CoreyRoth

@TerryB I've adopted this practice back in the 2007 days.  Since I used to run into issues activating features with stsadm in the same manner.  I'm not sure that there is any guidelines on this, but this is what I have been doing for some years.  

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Wednesday, April 11, 2012 11:07 PM by Pradip

This is good explanation.

To find the site collections where a specific feature is activated, Check this. paddyt.blogspot.in/.../powershell-to-find-site-collections.html

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Thursday, June 7, 2012 3:54 PM by FranckF

This is a merveillous post where all elements are clearly explained.

Regarding the message from @Amir, we are facing the same issue. We are developping a lot of publishing sites and today, we have to create "delay sections" or reactive twice the feature to really active it.

If you have any idea / solution, it would be great.

Thank you a lot.

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Tuesday, August 7, 2012 10:37 AM by SP2010Tq

Thanks for the snapshots.  Really Helps.  One additional note on the commands if you have site(s) defined with an PORT number use it as:  

get-spfeature -site http://sp2010dev:22511

# ???????? ???????? Feature ???? ???? ?????????????? | ??????????

Pingback from  ???????? ???????? Feature ???? ???? ?????????????? | ??????????

# Moving sites templates between servers and with feature dependencies

Pingback from  Moving sites templates between servers and with feature dependencies

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Thursday, November 22, 2012 11:58 PM by BGM

This is excellent!  Thank you very much!

# ???????? ???????? Feature ???? ???? ?????????????? | ??????????

Pingback from  ???????? ???????? Feature ???? ???? ?????????????? | ??????????

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Thursday, June 27, 2013 8:02 AM by Revanth

hi

features with event receivers are activating but event receivers are not firing when executed through power shell script

# re: Activating and Deactivating Features with PowerShell in SharePoint 2010

Tuesday, September 12, 2017 12:52 PM by Surbhika Kumari

Hey, Thanks for such a nice explanation. Can you please tell me the command to find out if the feature is activated from before or not?

One more thing, what shall I do if I have to activate the same feature for all the subsites under one site?

Leave a Comment

(required) 
(required) 
(optional)
(required)