How to find all the websites using enterprise features in SharePoint

A customer came up and said, we are having a large number of SharePoint Enterprise licenses and we want to know how many websites in our Farm are actually using Enterprise features of SharePoint.

In SharePoint, enterprise features are available by enabling the SharePoint Feature called as “PremiumWeb” with featureID as “0806D127-06E6-447a-980E-2E90B03101B8”. A good list of available enterprise features and their contents is available at https://blogs.msdn.com/ekraus/archive/2008/08/13/enterprise-features-exposed.aspx.

Now to find out which websites are actually have the Enterprise features (using them or not, is a totally different area of discussion) enabled for them, we should be easily able to iterate through the webs and their sub-webs and then check the feature list of each SPWeb object and see if we have “PremiumWeb” feature available or not. If the feature exists, that particular web has got enterprise features enabled.

Below is the code that I used to create a sample console application, which would give us a count of SPWebs which have got “PremiumWeb” feature enabled.

    1: namespace FindPremiumWebs
    2: {
    3:     class Program
    4:     {
    5:         static long featureCounter = 0;
    6:  
    7:         static void Main(string[] args)
    8:         {
    9:             if (args.Length > 0)
   10:             {
   11:                 Console.WriteLine("Checking webs under {0}...", args[0]);
   12:                 Console.WriteLine("Found {0} webs using Enterprise Features.", getAllPremiumWebs(args[0]));
   13:             }
   14:             else
   15:             {
   16:                 Console.WriteLine("URL not specified");
   17:             }
   18:         }
   19:         
   20:         public static long getAllPremiumWebs(string siteURL)
   21:         {
   22:  
   23:             using (SPSite site = new SPSite(siteURL))
   24:             {
   25:                 using (SPWeb web = site.RootWeb)
   26:                 {
   27:                     CheckSubWebs(web);
   28:                 }
   29:             }
   30:  
   31:             return featureCounter;
   32:         }
   33:  
   34:         private static void CheckSubWebs(SPWeb web)
   35:         {
   36:             foreach (SPWeb subWeb in web.Webs)
   37:             {
   38:                 foreach (SPFeature feature in subWeb.Features)
   39:                 {
   40:                     if (feature.Definition.DisplayName == "PremiumWeb")
   41:                     {
   42:                         featureCounter++;
   43:                     }
   44:                 }
   45:                 CheckSubWebs(subWeb);
   46:                 subWeb.Dispose();
   47:             }
   48:         }
   49:     }
   50: }

This console application expects that a URL of the root site be passed to it and it will iterate all the sub-webs under that root site and give out a total count of webs using (oops! enabled with) enterprise features.

As always… Happy Coding