Friday, December 4, 2015

Create Content Type Hub in SharePoint using PowerShell

Content type hub in SharePoint is a central location to manage content types. Any web application subscribed to the content type hub can consume content types from this store. Creating content type hub in SharePoint using Central Administration web UI is explained in my another article: How to Create Content Type Hub in SharePoint 2013, Now lets create content type hub in SharePoint 2013 using PowerShell.

PowerShell script to create Content Type Hub in SharePoint:
Creating content type hub in SharePoint involves three steps:

  1. Create an explicit Managed path for content type hub (optional)
  2. Create a top level site collection for content type hub
  3. Activate content type hub syndication feature
Here is the Script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$WebAppURL="http://intranet.crescent.com"
$ManagedPath="CTypeHub"
$HubOwner="Crescent\SPAdmin"

$WebApp = Get-SPWebApplication $WebAppURL

###  Step 1: Create Managed Path ###
#Check if the managed path exist already
$ManagedPathExists = Get-SPManagedPath -WebApplication $WebAppURL -Identity $ManagedPath -ErrorAction SilentlyContinue
 
 if ($ManagedPathExists -eq $null)
 {
    #Go ahead and create the managed path
    $CTypeHubPath=New-SPManagedPath –RelativeURL $ManagedPath -WebApplication $WebAppURL -Explicit
    Write-host "Managed Path Created!" -f Green
 }
 else
 {
    Write-Host "Managed path $ManagedPath already exists!" -f Yellow
 }

###  Step 2: Create Site Collection for Content type hub ###
#Check if ContentType hub site already exists
$CTypeHubURL = $WebAppURL+"/"+$ManagedPath

$CTypeHubExists = Get-SPSite $CTypeHubURL -ErrorAction SilentlyContinue

if($CTypeHubExists -eq $null)
{
    #Create site collection
    $CTypeHub = New-SPSite -Url $CTypeHubURL -Template 'STS#0' -OwnerAlias $HubOwner -Name "Content Type hub" 
}
else
 {
    Write-Host "Content Type Hub Site $CTypeHubURL already exists!" -f Yellow
 }

###  Step 3: Activate Content Type hub feature  ###
#Check if ContentType hub feature is already enabled
$Feature = Get-SPFeature -site $CTypeHubURL –Identity "ContentTypeHub" -ErrorAction SilentlyContinue 

If($Feature -eq $null) 
{      
    #Activate feature
    Enable-SPFeature –Identity "ContentTypeHub" –url $CTypeHubURL -Force -ErrorAction SilentlyContinue 
    Write-Host "Activated Content Type hub feature" -F Green 
}
else
{
    write-host "Content Type Hub Feature already enabled!" -F Yellow
}
Don't forget to set the content type hub in Managed Metadata service application: Setting up Content Type Hub in Manage Metadata Service Application



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...