Created
October 20, 2021 11:05
-
-
Save vtml/6c0c98fe4a451198c36739f0c49a1c84 to your computer and use it in GitHub Desktop.
Ultimate Sitecore Publishing Powershell Script
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
param ( | |
[Parameter(HelpMessage = "If ItemIds are specified, only that item will publish. The Item ID should be in the format of {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}")] | |
[string[]] | |
$ItemIds = @(), | |
[Parameter(HelpMessage = "Target Database name. e.g. Web")] | |
[string[]] | |
$TargetDatabases, | |
[Parameter(HelpMessage = "All languages will publish unless explicitly specified")] | |
[string[]] | |
$Languages, | |
[Parameter(HelpMessage = "Site Publish Mode")] | |
[ValidateSet("Incremental", "Smart", "Republish")] | |
[string] | |
$PublishMode = "Incremental" | |
) | |
$ErrorActionPreference = 'Stop' | |
$database = Get-Database -Name "master" | |
$targets = $TargetDatabases | |
foreach($publishingTarget in [Sitecore.Publishing.PublishManager]::GetPublishingTargets($database)) { | |
$targets += Get-Database -Name $publishingTarget[[Sitecore.FieldIDs]::PublishingTargetDatabase] | |
} | |
$languages = [Sitecore.Data.Managers.LanguageManager]::GetLanguages($database) | |
if ($ItemIds.length -gt 0) | |
{ | |
foreach($itemId in $ItemIds) | |
{ | |
$item = Get-Item -Path "master:" -ID $ItemId | |
# Item publish with children | |
[Sitecore.Publishing.PublishManager]::PublishItem($item,$targets,$languages,$true,$true,$true) | |
} | |
} | |
else { | |
# All Items | |
[Sitecore.Publishing.PublishManager]::PublishSmart($database,$targets,$languages) | |
[Sitecore.Publishing.PublishManager]::PublishIncremental($database,$targets,$languages) | |
[Sitecore.Publishing.PublishManager]::Republish($database,$targets,$languages) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment