Created
December 12, 2014 11:11
-
-
Save rheid/d1331c60508983a347d4 to your computer and use it in GitHub Desktop.
Publish Content Types Using Powershell - SharePoint 2013
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Check to ensure Microsoft.SharePoint.Powershell is loaded | |
$snapin = Get-PSSnapin | Where-Object{$_.Name -eq ‘Microsoft.SharePoint.Powershell’} | |
if ($snapin -eq $null) { | |
Write-Output “Loading SharePoint Powershell Snapin” | |
Add-PSSnapin “Microsoft.SharePoint.Powershell” | |
} | |
$webAppURL = “http://intranet.mycompany.com” | |
#Get the site collection of your content type hub | |
$site = Get-SPSite “$webAppUrl/metadata/contenttypehub” | |
#Get the root web of the about site collection | |
$web = $site.RootWeb | |
#Create a new publisher object | |
$publisher = New-Object Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher($site) | |
# Function to publish the content types | |
function PublishContentType($contentTypeName) | |
{ | |
Write-Host “Publishing Content Type $contentTypeName” -foregroundcolor Green | |
$cType = $web.ContentTypes[$contentTypeName] | |
$publisher.Publish($cType) | |
} | |
Write-Host ” “ | |
Write-Host “PUBLISHING CONTENT TYPES” -foregroundcolor Green | |
PublishContentType(“Content Type One”) | |
PublishContentType(“Content Type Two”) | |
PublishContentType(“Content Type Three”) | |
PublishContentType(“Content Type Four”) | |
PublishContentType(“Content Type Five”) | |
PublishContentType(“Content Type Six”) | |
PublishContentType(“Content Type Seven”) | |
PublishContentType(“Content Type Eight”) | |
PublishContentType(“Content Type Nine”) | |
PublishContentType(“Content Type Ten”) | |
Write-Host ” “ | |
Write-Host “RUNNING TIMER JOBS” -foregroundcolor Cyan | |
Write-Host “Running the Content Type Hub time job” -foregroundcolor Cyan | |
Get-SPTimerJob MetadataHubTimerJob | Start-SPTimerJob | |
# For the Content Type Subscriber timer job you have to get acquire it for specific web application | |
$job = Get-SPTimerJob -Identity MetadataSubscriberTimerJob -WebApplication $webAppURL | |
if ($job -ne $null) | |
{ | |
Write-Host “Running the Content Type Subscriber timer job for web application $webAppURL” -foregroundcolor Cyan | |
$job | Start-SPTimerJob | |
Write-Host “Run the admin action” | |
Start-SPAdminJob -ErrorAction SilentlyContinue | |
} | |
Write-Host “Done!!!” | |
#keep the window opent for 5 minutes | |
Sleep -Seconds 300 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment