Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Adapted the functions written by Nick Wesselman to work directly in SPE.
<#
.NOTES
Copied from Nick Wesselman's video https://www.youtube.com/watch?v=tXTbMRVF0ts
#>
function Start-Publish {
param(
[string]$Source = "master",
[string]$Target = "web"
)
$sourceDb = [Sitecore.Data.Database]::GetDatabase($Source)
$targetDb = [Sitecore.Data.Database]::GetDatabase($Target)
$languages = [Sitecore.Globalization.Language]::GetLanguages($sourceDb)
$handle = [Sitecore.Publishing.PublishManager]::PublishSmart($sourceDb, @($targetDb), $languages)
$handle.ToString()
}
function Check-PublishStatus {
param(
[string]$HandleName
)
$handle = [Sitecore.Handle]::Parse($HandleName)
[Sitecore.Publishing.PublishManager]::GetStatus($handle)
}
$handle = Start-Publish
$status = Check-PublishStatus -HandleName $handle
$processed = -1
while(-not $status.IsDone) {
if($status.Processed -ne $processed) {
$processed = $status.Processed
Write-Host "Publishing: $($processed) items"
}
Start-Sleep -Seconds 1
$status = Check-PublishStatus -HandleName $handle
}
Write-Host "Publishing: done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment