3

I have a Sandbox feature that was deployed to my SharePoint 2013 environment. I say "Sandbox" because if I run:

Get-SPFeature

It doesn't come up in the list. But if I run:

Get-SPFeature -Site <site url>

Then I can see my feature. Now, I'm trying to remove it using:

Uninstall-SPFeature -Identity <guid>

However I get the following error:

Uninstall-SPFeature : Cannot find a Feature object with Path or Id: <guid> in scope Local farm.
At line:1 char:1
+ Uninstall-SPFeature -Identity <guid>
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Share...ninstallFeature: SPCmdletUninstallFeature) [Uninstall-SPFeature], SPCmdletPipeBindException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletUninstallFeature

So I can only assume that this command only removes farm features from the server, and the TechNet page doesn't explicitly say anything about this. How can I remove this feature then?

EDIT 1: It may be worthwhile to know that I installed this feature through a sandbox solution WSP, by uploading it to the Solutions gallery and activating it there as discussed in this post.

EDIT 2: Thanks for all the answers so far. I've sort of managed to remove it using Uninstall-SPUserSolution and then Remove-SPUserSolution. I say "sort of" because the feature doesn't show up anymore when I do Get-SPFeature, nor the solution when I do Get-SPUserSolution. Apparently the feature was packed inside a sandbox solution. However the problem is still not solved, because the only thing the feature does is to deploy a site page like http://blablabla/FeatureDeployed, and so although the feature and the solution were removed, the site page still remains in the same address. Shouldn't the site page be deleted when the feature is removed?

3 Answers 3

3

I think the Powershell commandlets you are looking for are:

Disable-SPFeature, which is the equivalent of going to the "Manage Site Features" page and clicking the "Deactivate" button. Disable-SPFeature has a Force parameter, and a URL parameter which:

Specifies the URL of the Web application, site collection, or Web site to which the Feature is being disabled.

so you can target it to the specific scope necessary.

And then you want:

Uninstall-SPUserSolution, which is the equivalent of going to the Solutions Gallery on the site collection and clicking "Deactivate"

And:

Remove-SPUserSolution, which is the equivalent of going to the Solutions Gallery on the site collection and Deleting the sandbox WSP file from the Solutions Gallery.

4
  • The commands are right in the sense that they seem to partially do the job, but the feature is still not gone. See my EDIT 2 for more details. Thanks Dylan Commented Jan 28, 2016 at 14:23
  • 1
    @sedulam, in response to your Edit 2 - not all assets installed by a Feature are removed when the Feature is deactivated. Some things would need to be explicitly removed through a FeatureDeactivating feature receiver. In my experience, site columns and content types (when not in use) seem to get removed, but other assets, like scripts, CSS files, or site pages, do not get removed. Commented Jan 28, 2016 at 15:00
  • Thanks! I suppose that FeatureDeactivating event receiver must be put inside the feature code right? Not something I can just put in a script to be run when we want o uninstall the feature. Commented Jan 28, 2016 at 15:05
  • 1
    Yes, technically the FeatureDeactivating event receiver needs to be put in the feature code, but if you do not have access to modify that, and you know exactly what assets you want to target to remove and know where they are, creating a script to remove them when you want to uninstall the feature seems totally reasonable. Commented Jan 28, 2016 at 15:09
1

I saw a similar behavior once when a feature became "orphan" following some error during a solution upgrade test in one of my development environments. Some of the info you give aren't really strict, so forgive me for my guessing, but here are some info that saved me back then.

Turns out that the Uninstall-SPFeature -Identity <guid> command is the most "vulnerable" and prone to crash if the feature is in an invalid status. You should try some equivalent way to delete the feature and see if that work instead - otherwise we may need more info to diagnose the problem.

For starting - try using the display name of the feature instead of the GUID (see this example for further details), then call .Delete() on the resulting feature definition instance. This worked for me once.

$featureToDelete = Get-SPFeature -Site "<siteurl>" | ? { $_.DisplayName -eq "Feature display name" }
$featureToDelete.Delete()

If even this fail, it may be worth giving good ol' stsadm a try:

stsadm -o uninstallfeature -id <Guid>

Its internal implementation isn't the same of the Powershell based version, and even if deprecated isn't rare for PowerShell to actually work for situations where PowerShell fails...


UPDATE: based on the latest update to the question, the problem wasn't a "stuck/corrupted" state for the feature in the SharePoint configuration db like I feared, but simply a missing step in the sandboxed solution removal process. For these reason the above info are made obsolete in a way - I will still leave them here as a reference hoping that they may be useful to others users with similar problems, but I will convert the post to community wiki.

4
  • Hi! Both methods failed, the first one gave me the error: Method invocation failed because [Microsoft.SharePoint.SPUserSolution] doesn't contain a method named 'Delete'. At line:1 char:1 + $featureToDelete.Delete() + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound And the 2nd one gave me: Feature with Id '<guid>' is not installed in this farm. The feature was not uninstalled. I'm also going to add some information to my post that may shed more light on this. Commented Jan 27, 2016 at 10:47
  • @sedulam Sorry . I made an error in the answer - I gave you the wrong instruction (the one I listed is to get the solution, not the feature). I will fix it right away, give me a minute Commented Jan 27, 2016 at 17:42
  • 1
    Should be this one, sorry again @sedulam. But let me ask you another thing that came to mind because of this error. Your feature... you said it is sandboxed - I suppose you had a sandboxed solution containing it deployed then... Is this feature actually "orphan" as now or the solution is still there? Have you tried to simply deactivate the feature (if it is not already) and then deactivating the sandbox solution? Commented Jan 27, 2016 at 17:57
  • Yes, you're right about the command. :) I've added more info to the problem in my EDIT 2, because although the commands seem to help, the problem is still not solved. Commented Jan 28, 2016 at 13:50
0

If you want to disable Sandbox Solutions (I'm assuming that is what you mean by Sandbox), you can just stop the Sandbox service in Central Admin -> Manage Services on Server, and stop the Microsoft SharePoint Foundation Sandboxed Code Service.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.