Friday, November 18, 2011

Use PowerShell to add a new feature to an existing tenant subscription in a SharePoint 2010 Multi-Tenant Environment.


A pre-existing SharePoint 2010 multi-tenant farm has been pre-configured with feature packs, subscriptions and associated tenants.  If you need the ability to add a feature, or rather, make a feature available to one or many of these pre-existing tenants, the script below will do the job.

Note: While the script takes the URL of an existing site, the actual feature will be added (and thus, become available) to all tenants that share the feature pack used by the tenant that owns the URL.  If you need to add a single feature to a single tenant, you will need to create a new feature pack and modify the tenant’s subscription properties accordingly! 


function Add-FeatureToTenantSubscription(

      [System.String] $tenantSiteURL,

      [System.String] $FeatureDirectory)


      #Check and Add SharePoint cmdlets if required:

      if ((Get-PSSnapin | `

            where { $_.Name -eq "Microsoft.SharePoint.PowerShell" } | `

            Measure-Object).Count -lt 1)


            Add-PSSnapIn Microsoft.SharePoint.PowerShell



      #Get the Subscription Config Object:

      $subscriptionConfig = Get-SPSiteSubscription | `

            ? {$tempSub = $_; $tempSub.Sites | `

            ? { $_.Url -eq $tenantSiteURL }} | `



      #Check to ensure we found one:

      if ($null -eq $subscriptionConfig)


            Write-Host "Could not find a subscription with url $tenantSiteURL...";




            #Grab Reference to the Feature:

            $feature = Get-SPFeature `

                  -Identity $FeatureDirectory `

                  -ErrorAction SilentlyContinue;


            #And Check to make sure it exists:

            if ($null -eq $feature)


                  Write-Host "Could not find a feature with the directory $FeatureDirectory ?";




                  #Add the Feature Pack and update:

                  $subscriptionConfig.FeaturePack.Add($feature) | `



                  Write-Host "Feature $FeatureDirectory added to Feature Pack `

                  Associated with the subscription used by the url $tenantSiteURL !";




To use the function:

$tenantSiteURL = "";

$FeatureDirectory = "MyriadTech.SharePoint.ProfilePhoneBook";

Add-FeatureToTenantSubscription $tenantSiteURL $FeatureDirectory;


(I guess you’ll have to take my word the screen shots were taken from a multi-tenant environment)

Before running the script:


After Running the script:


No comments:

Post a Comment