Create Content Type Hub in SharePoint using PowerShell
The 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 a content type hub in SharePoint using Central Administration web UI is explained in another article: How to Create Content Type Hub in SharePoint 2013?, Now let’s create a content type hub in SharePoint 2013 using PowerShell.
PowerShell Script to Create Content Type Hub in SharePoint:
Creating a content type hub in SharePoint involves three steps:
- Create an explicit Managed path for content type hub (optional)
- Create a top level site collection for content type hub
- Activate content type hub syndication feature
- Set Content Type Hub URL in MMS Service Application
Here is the script to create a content type hub in SharePoint 2013 using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Configuration Parameters
$WebAppURL="https://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
}
### Step 4: Set Content Type Hub URL in MMS Service App
#Set the Content Type Hub URL in MMS Application
$MMS = Get-SPServiceApplication | Where-Object {$_.TypeName -eq "Managed Metadata Service"}
Set-SPMetadataServiceApplication -Identity $MMS -HubUri $CTypeHubURL
#Update the Managed Metadata Service Proxy to consume from the content type hub
$MMSProxy = Get-SPServiceApplicationProxy | Where-Object {$_.TypeName -eq "Managed Metadata Service Connection"}
Set-SPMetadataServiceApplicationProxy -Identity $MMSProxy -ContentTypeSyndicationEnabled -ContentTypePushdownEnabled
Here is another post on changing content type hub URL in Managed Metadata service application: Change Content Type Hub in Manage Metadata Service Application using PowerShell