SharePoint Dragons

Nikander & Margriet on SharePoint

SharePoint 2010: Enable-SPFeature vs good old stsadm

Installing SharePoint 2010 features via SharePoint solutions can easily be done via the good old stsadm tool, using something like this:

stsadm -o addsolution -filename mine.wsp
stsadm -o deploysolution -immediate -name mine.wsp -allowGacDeployment
stsadm -o execadmsvcjobs
iisreset

stsadm -o activatefeature -name mine -url http://mysrv
iisreset

The equivalent in PowerShell is also pretty easy, doing something like this:

Add-SPSolution “C:\software\myfolder\mine.wsp”
stsadm -o execadmsvcjobs

Install-SPSolution –Identity mine.wsp –GACDeployment
stsadm -o execadmsvcjobs

Enable-SPFeature –Identity mine –url http://mysrv
stsadm -o execadmsvcjobs

For symmetry purposes, and if you work in IT you need to have some love for symmetry, we’re also including how uninstalling it via both stsadm and PowerShell. First, the stsadm tool:
stsadm -o deactivatefeature -name mine.wsp -url http://mysrv
iisreset

stsadm -o retractsolution -name mine.wsp -immediate
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name mine.wsp -override
iisreset

In PowerShell, installing goes like this:
Disable-SPFeature –Identity mine –url http://mysrv
stsadm -o execadmsvcjobs

Uninstall-SPSolution –Identity mine.wsp
stsadm -o execadmsvcjobs

Remove-SPSolution –Identity mine.wsp
stsadm -o execadmsvcjobs

Optionally, check out if it worked by getting a list of all features for a site collection:

get-spfeature site http://mysrv

Now, let’s get on to the reason we wrote the blog post. What should you choose: Enable-SPFeature or the good old stsadm tool? Surprisingly, when it comes to actually activating features, we’re going go with the good old stsadm tool.

Why? The Enable-SPFeature PowerShell command doesn’t give extensive feedback regarding everything surrounding the feature activation. In other words, it might tell you that feature activation succeeded, but won’t tell you anything if custom code in the FeatureActivated event receiver (which runs after feature activation) throws an exception. The execution of custom code in a FeatureActivated event receiver is usually the tricky part of an installation, so this is not ideal.

The stsadm equivalent of  the Enable-SPFeature PowerShell command, stsadm -o activatefeature -name mine -url http://mysrv , does provide this information and displays the error message of the exception. This is a lot more helpful and the behavior you’re typically looking for. More than that, it sure looks like the Feature Activation deployment step in Visual Studio 2010 does exactly the same thing.

In other words, when it comes to feature activation, we still prefer the use of the good old stsadm tool!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: