Wednesday 23 January 2013

SharePoint 2010/2013 Multi-Tenancy: Delete an existing tenant and create a new tenant and assigned same OU

Delete an existing tenant and create a new tenant and assign same OU:


Delete tenant means delete subscription ID from farm. In share Point 2010 Every Tenant is having its own unique subscription ID.

Its quite difficult to remove connection between Subscription ID and OU.On this I did some R&D and found that if you remove subscription ID from farm all connection to OU will not deleted means some entries still present in related DBs. So until you remove all the entries from share Point DBs you cant use same OU for different tenant/subscription ID. Microsoft never advise to make changes in DB directly, but I did that and it was successful. If you don't want to get this process I have a new trick to do this.

*Don't delete Subscription ID

*Just delete all the site collection present in this.

* Assign this subscription ID to new tenant.

In this way You can easily assign subscription ID to new teanant with same OU connection.


Scripts are as below:

// This will give you all subscription ID
$sub = get-spsitesubscription

//Dont use this command:

remove-spsitesubscription -identity "$sub"

//Delete all the site collection manually from centraladmin or use powershell command related to subscription ID

Try the folowing ps script to create new Tenant and can use original ( previous) OU:

Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0

//Note down your scubscription ID which you want to use and we will use later in the script.


Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0

# farm details - update to reflect environment
$customerName = "<OU Name>"
$customerTenantAdmin = "<OU Admin with domain>"   
$ouName= "<OU Name>"
$fullOUPath = 'OU=<OU PATH>,OU=<OU PATH>,DC=<Domain Name>,DC=<Domain Name>'
$fullTenantURL = "http://<testsiteurl>"
$customerFeatures = $customfeature
$hostingMainURL = "http://<HostingWebApplicationURL>"
$upaProxyName = "<User Profile Proxy> Farm Tenant User Profile Service Proxy"
$mmsProxyName = "<User MetaData Proxy> Farm Tenant Managed Metadata Service Proxy"

# feature packs - update after creating them
$foundationFeatures = "479a3211-b2c8-4efd-b09e-a11194c8ef79"
$standardFeatures = "400e72d3-7a97-4e28-8a9a-ac0f6ffba4e6"
$enterpriseFeatures = "0da79437-5735-4550-b4b1-2f9608ecb328"
$customfeature="0da79437-5735-4550-b4b1-2f9608ecb328"
$a = Read-Host "Have you added the user running this script to *permissions* on the UPA?"
    $webApp = Get-SPWebApplication $hostingMainURL
    # create new Site Subscription
    Write-Host "Creating Site Subcription..."
    //$sub = New-SPSiteSubscription
$sub = "<use the existing old Subscription ID here>"


    # assign feature pack and configure the OU to use in the People Picker for the Subscription
    Write-Host "Assiging Feature Pack and configuring People Picker..."
   
    Set-SPSiteSubscriptionConfig –id $sub -FeaturePack $enterpriseFeatures -UserAccountDirectoryPath $fullOUPath


function ProvisionTenant($enterpriseFeatures,$customerName, $customerTenantAdmin, $customerFeatures, $hostingMainURL, $upaProxyName, $mmsProxyName, $foundationFeatures, $ouName, $fullTenantURL, $fullOUPath, $webApp, $sub)
{
    Write-Host "Provisioning Tenant..."
    Write-Host "Name: $customerName"
    Write-Host "Admin: $customerTenantAdmin"


   
    $a = Read-Host "Are Details ok ?"

    # grab the web app


    # create the "main" member site (we need a site at the root to use Host Headers and Managed Paths in the following cmdlets)
    Write-Host "Creating Root Site..."
    New-SPSite -url "$fullTenantURL" -SiteSubscription $sub -HostHeaderWebApplication $webApp -owneralias $customerTenantAdmin -template BLANKINTERNETCONTAINER#0

    # create Tenant Admin site
    Write-Host "Creating Tenant Admin site..."
    New-SPSite -url "$fullTenantURL/admin" -SiteSubscription $sub -HostHeaderWebApplication $webApp -owneralias $customerTenantAdmin -template tenantadmin#0 -AdministrationSiteType TenantAdministration

    # everything else needs standard
    if (!($customerFeatures -eq $foundationFeatures))
    {
        Write-Host "Tenant has SharePoint Server features"
        # create a mysite host
        Write-Host "Creating My Site Host..."
        New-SPSite -url "$fullTenantURL/mysites" -SiteSubscription $sub -HostHeaderWebApplication $webApp -owneralias $customerTenantAdmin -template SPSMSITEHOST#0

        # configure the MySites host, MySites path, Naming Resolution and Profile Sync OU for the Subscription
        Write-Host "Configuring Tenant Profile Config..."
        $upaProxy = Get-SPServiceApplicationProxy | where-object {$_.DisplayName -eq $upaProxyName}
    $upaProxy
        SET-SPSiteSubscriptionProfileConfig -id $sub -SynchronizationOU $ouName -MySiteHostLocation "$fullTenantURL/mysites" -MySiteManagedPath "/mysites/personal" -SiteNamingConflictResolution "None" -ProfileServiceApplicationProxy $upaProxy

        # create a site for the Content Type Gallery
        Write-Host "Creating Content Type Gallery..."
        New-SPSite -url "$fullTenantURL/cthub" -SiteSubscription $sub -HostHeaderWebApplication $webApp -owneralias $customerTenantAdmin -template sts#0

        # configure the Content Type Gallery for the Subscription
        Write-Host "Configuring Tenant Content Type Gallery..."
        $mmsProxy = Get-SPServiceApplicationProxy | where-object {$_.DisplayName -eq $mmsProxyName}
    $mmsProxy
        # ContentTypeHub feature activation may fail - if so activate manually
        Set-SPSiteSubscriptionMetadataConfig -identity $sub -serviceProxy $mmsProxy -huburi "$fullTenantURL/cthub" -SyndicationErrorReportEnabled
        Write-Host "Activating Content Type Hub..."
        Enable-SPFeature -Identity ContentTypeHub -url "$fullTenantURL/cthub"
       
       
    }


    #Set-SPSiteSubscriptionEdiscoveryHub - create an ediscovery hub, requires site - -SearchScope 1 - all of the sub
   
    Write-Host "Tenant Provisioned!"
    return $sub

}

*You require SharePoint 2010 SP1 because SET-Sitesubscription powershell command run only SharePoint 2010 SP1 and later version.  

You can also use same concept for SharePoint 2013 :)  it works with that too...

3 comments:

  1. Was this ever tested on Sharepoint 2013? Did it actually work successfully?

    ReplyDelete
  2. So this will allow you to move away form Multi-Tenancy in a migration from 2010 to 2013?

    ReplyDelete