Skip Ribbon Commands
Skip to main content

Anders Rask on SharePoint


Anders Rask on SharePoint > Posts > Using PowerShell to fetch features that should be disabled / enabled
May 31
Using PowerShell to fetch features that should be disabled / enabled

​I always use PowerShell when ever I am provisioning artifacts to our customers SharePoint farms.

Provisioning solutions and features can be tricky, and there are alot of caveats both in the way solutions are structured, what features that needs to be re-activated or upgraded, solution dependencies, feature dependencies etc.

Often re-installing or upgrading a solution isn't enough: you also need to re-enable or upgrade the relevant features. For this I use QueryFeatures in combination with PowerShell, so that I first check all places where a given feature is used, instead of disabling it and enabling it on all Site Collections:

$feature = Get-SPFeature -Identity MyFeature
$siteUrls = Get-SPSite -Limit All | %{$_.QueryFeatures($feature.Id, $false)} | %{$_.Parent.Url}
$siteUrls | %{ Disable-SPFeature -Identity $feature.Id -Url $_ -Confirm:$false}

# logic to upgrade or re-install
# solutions goes here

$siteUrls | %{ Enable-SPFeature -Identity $feature.Id -Url $_ -Confirm:$false }

You can also use this to upgrade features:

$feature = Get-SPFeature -Identity MyFeature
$siteUrls = Get-SPSite -Limit All | %{$_.QueryFeatures($feature.Id, $false)} | %{$_.Upgrade($false)}

Two things to note:

Dont use -Force on your feature or solution cmdlets. First off when you use force, all exceptions is swallowed. That means if you have feature receiver code that fails, you will never notice. Another lesser known problem is, that using force will trigger a feature upgrade. A look into SPFeature class with Reflector reveals this:

internal void Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, bool fForce)
    if (fForce)
            this.Upgrade(siteParent, webParent, fForce);
//more code here
This of course is a problem, since you probably don't expect this to happen when activating a feature.
The other issue to be aware of, is that if you have deleted sites (SPWeb) in your recycle bin.
I have experienced that at least SPSite.QueryFeatures() throws exceptions internally that is not caught, when it tries to fetch SPWeb's that are deleted.
I take it that this is because the feature instances are stored in a seperate database table, that is not updated with a "deleted" flag when a site is deleted. This means that when QueryFeatures() fetches feature instances that belongs on deleted SPWeb's, and hence throws an exception.
This looks like a bug in SharePoint and makes QueryFeatures() method rather tricky to use. I will post updates on this if I find good workarounds or bug fixes.





I am getting here about something happened dastardly deed and making the better popeye would be perfect. The wondered brought muscles to appear and great technical recliner and impressive rescue us some.
 on 7/4/2018 8:00 AM

Re: Using PowerShell to fetch features that should be disabled / enabled

Our maths homework helpers writers are expertise in writing all type of assignment of maths homework help at cheaper rate in limited time and also help students to achieve higher marks in maths homework help.

 on 7/18/2018 12:45 AM


<a href=""> Check Support</a>
[url=]Check[/url]     re CAPTCHA V1 IS SHUTDOWN                                                                          
 on 8/1/2018 6:22 AM

Movers and Packers

One very query that a lot of students ask is, “Where am I going to remain once I arrive on Indian native.” A wide range of scholars decide to survive Indian native either Indian native that is their preference.
Visit Site:
 on 8/1/2018 6:22 AM

Movers and Packers

Indian native they are needed to live in an on- Indian native dormitory for a certain time interval of your energy as well as. Coping with dorms often indicates being confined to tight quarters with a individual or people you may or may not know.
Visit Site:
 on 8/1/2018 6:23 AM

Movers and Packers

So you are probably wondering, “How can I create the most out of my little living space?” Well, keep studying below for nice storage place recommendations that will help you do Indian native that.
Visit Site:
 on 8/1/2018 6:23 AM

Movers and Packers

Put it in the Closet- Yes, this may seem like an Indian native one, but that is what your clothing collection is there for. Determine out strategies to Indian native your clothing collection  to acquire the most out of the available placed you have.
Visit Site:
 on 8/1/2018 6:23 AM

Movers and Packers

There are even strategies to keep factors organized within your clothing collection. One outstanding option to consider would be to buy closest dividers that allow you to organize your clothing collection into particular sections.
Visit Site:
 on 8/1/2018 6:23 AM


 on 8/1/2018 6:28 AM

Packers and Movers

This is the whole essential guide for you all workplace shifters in Pune how to program and what are the key points you must know before you pack and move. Companies shifting is very much typical perform as if many factors are there to be focusing on, like saving perform time, involving the employs, keeping track of all the main and important information of workplace while item overall look and Movers. More info visit:
 on 8/1/2018 6:28 AM
1 - 10Next

Add Comment


Body *

Migrated Source URL

Commentator Name

Commentator Email

BotCheck *

Are you human? What is the sum of fifty-two minus ten?