Monday 7 March 2011

How to enable and disable a Feature with PowerShell

In a previous post I showed you how to uninstall a feature with Powershell. That command is going to be quite useful when you have to do some development with workflows and event receivers. Event receivers are quite stable but workflows are a different subject. Even when they are fired, sometimes they don't work in the way you expect.

Event receivers always work like you expect, just because they are a bunch of events already defined, when workflows mix 3.0 .NET WF with 3.5 .NET WF with native sharepoint 2010 modules.

The following commands will save you plenty of work, and I recommend to use them all the time, to be sure that what you are deploying is the right version of your Workflow or Event Receiver.

To enable a feature just type the following command in Powershell (replace nameofyourfeature with the name of the featurae you want to enable. Type the url where your feature lives):

Get-SPFeature | Where-Object {$_.DisplayName -eq 'nameofyourfeature '} | Enable-SPFeature -Identity {$_.Id} -Url http://myserver/sites/docs

To disable the feature just type the following command in Powershell (replace nameofyourfeature with the name of the featurae you want to enable. Type the url where your feature lives):

Get-SPFeature | Where-Object {$_.DisplayName -eq 'nameofyourfeature '} | Disable-SPFeature -Identity {$_.Id} -Url http://myserver/sites/docs


Conclusion: Powershell can beat any user interface in Sharepoint 2010. With Powershell we will be able to reach any issue we have with features. The Web UI still quite weak comparing with the power of this shell.

No comments: