Created
November 4, 2014 21:41
-
-
Save DominicCronin/786e8b00d21c538b1de5 to your computer and use it in GitHub Desktop.
Create Tridion Publications
This file contains hidden or 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
| # Depends on Tridion Powershell Modules (http://code.google.com/p/tridion-powershell-modules/) | |
| function createPublication { | |
| Param( | |
| [parameter(Mandatory=$true)] | |
| [ValidateNotNullOrEmpty()] | |
| $core, | |
| [parameter(Mandatory=$true)] | |
| [ValidateNotNullOrEmpty()] | |
| [string]$title, | |
| [string]$key, | |
| [string[]]$parents, | |
| [switch]$Passthru | |
| ) | |
| write-host "Creating publication $title" | |
| $newPublication = $core.GetDefaultData([Tridion.ContentManager.CoreService.Client.ItemType]::Publication,"",$null) | |
| $newPublication.Title = $title | |
| if ($key -eq [string]::Empty){ | |
| $newPublication.Key = $title | |
| } | |
| else { | |
| $newPublication.Key = $key | |
| } | |
| foreach ($parent in $parents){ | |
| $link = new-object Tridion.ContentManager.CoreService.Client.LinkToRepositoryData | |
| if ($parent -match "^tcm:"){ | |
| $link.IdRef = $parent | |
| } elseif ($parent -match "^/webdav"){ | |
| $link.WebDavUrl = $parent | |
| } else { | |
| continue | |
| } | |
| $newPublication.Parents += $link | |
| } | |
| if ($Passthru){ | |
| $core.Create($newPublication, (new-object Tridion.ContentManager.CoreService.Client.ReadOptions)) | |
| } | |
| else { | |
| $core.Create($newPublication,$null) | |
| } | |
| } | |
| function createStructureGroup($core, [string]$parentId, [string]$title, [string]$directory, [switch]$Passthru){ | |
| write-Host "Creating Structure Group $title" | |
| $newStructureGroup = $core.GetDefaultData([Tridion.ContentManager.CoreService.Client.ItemType]::StructureGroup, $parentId, $null) | |
| $newStructureGroup.Title = $title | |
| $newStructureGroup.Directory = $directory | |
| if ($Passthru){ | |
| $core.Create($newStructureGroup, (new-object Tridion.ContentManager.CoreService.Client.ReadOptions)) | |
| } | |
| else { | |
| $core.Create($newStructureGroup, $null) | |
| } | |
| } | |
| function createImportPublications($core, $chainMasterTitle="000 Empty", $masterTitle="100 Master", $webTitle="100 Example Site", $rootStructureGroup="Home") { | |
| $chainMasterPub = createPublication $core $chainMasterTitle -Passthru | |
| $rsg = createStructureGroup $core $chainMasterPub.Id $rootStructureGroup $rootStructureGroup -Passthru | |
| $masterPub = createPublication $core $masterTitle -parents @($chainMasterPub.Id) -Passthru | |
| createPublication $core $webTitle -parents @($masterPub.Id) | |
| } | |
| $core = Get-TridionCoreServiceClient | |
| createImportPublications $core "TRI 000 Empty" "TRI 100 Master" "TRI 400 Example Site" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment