Skip to content

Instantly share code, notes, and snippets.

@hombreDelPez
Last active December 9, 2019 05:43
Show Gist options
  • Save hombreDelPez/b73c5df4e1818debc95e2ba5886cd8b4 to your computer and use it in GitHub Desktop.
Save hombreDelPez/b73c5df4e1818debc95e2ba5886cd8b4 to your computer and use it in GitHub Desktop.
Sitecore PowerShell script to list all unpublished pages
<#
.SYNOPSIS
Lists the pages which are not published yet (in the current version or any version at all).
.NOTES
Manuel Fischer
#>
function Get-AllUnpublishedPages {
Get-ChildItem -Path $homeFolder -Recurse | IsPage | IsPublished
}
filter IsPage {
$templates = Get-ItemTemplate $_
$baseTempls = $templates.BaseTemplates
foreach($baseTempl in $baseTempls) {
$id = $baseTempl.ID.ToString()
# Template: /sitecore/templates/User Defined/Master/Pages/Page with Shared Footer
if($id -eq "{5E9159CF-19F4-41D1-91F4-007B7B5BA401}") {
$_
Return
}
# Template: /sitecore/templates/User Defined/Master/Pages/Page without Shared Footer
if($id -eq "{F988428C-76E0-4774-B30E-A0BD63D3E639}") {
$_
Return
}
}
}
filter IsPublished {
$path = $_.ItemPath -replace ('/','\')
$itemExists = Test-Path -Path "web:$($path)"
if(!$itemExists) {
Get-AllLanguageVersions $_
} else {
Get-MissingLanguageVersions $_
}
}
function Get-AllLanguageVersions ($currentItem) {
$result = New-Object System.Collections.ArrayList
$itmPath = $currentItem.ItemPath -replace ('/','\')
foreach($lang in $contentLanguages) {
$langV = Get-Item -Path "master:$($itmPath)" -Language $lang.Name
if($langV -ne $null) {
$dummy = $result.Add($langV)
}
}
$result
}
function Get-MissingLanguageVersions ($currentItem) {
$result = New-Object System.Collections.ArrayList
$itmPath = $currentItem.ItemPath -replace ('/','\')
foreach($lang in $contentLanguages) {
$langVerMas = Get-Item -Path "master:$($itmPath)" -Language $lang.Name
if($langVerMas -ne $null) {
$langVerWeb = Get-Item -Path "web:$($itmPath)" -Language $lang.Name
if ($langVerWeb -eq $null) {
$dummy = $result.Add($langVerMas)
}
}
}
$result
}
$database = "master"
$homeFolder = "$($database):\sitecore\content\Master\Home"
$homeExists = Test-Path -Path $homeFolder
if(!$homeExists) {
Show-Alert "Der Home-Ordner wurde nicht gefunden!"
} else {
$contentLanguages = $(Get-Item $homeFolder).Languages
$items = Get-AllUnpublishedPages
if($items.Count -eq 0){
Show-Alert "Es wurden keine Seiten gefunden, die noch nicht in der ausgewählten Version veröffentlicht wurden."
} else {
$props = @{
Title = "Unpublizierte Seiten - Resultate"
InfoTitle = "Seiten, die noch nicht veröffentlicht wurden in der ausgewählten Version."
InfoDescription = "Zeigt die Seiten an, die noch nicht in der ausgewählten Version veröffentlicht wurden."
PageSize = 25
}
$items |
Show-ListView @props -Property @{Label="Page Name"; Expression={$_.DisplayName} },
@{Label="Page Template"; Expression={$_.TemplateName} },
@{Label="Language"; Expression={$_.Language} },
@{Label="Created"; Expression={$_.__Created} },
@{Label="Updated"; Expression={$_.__Updated} },
@{Label="Updated by"; Expression={$_."__Updated by"} },
@{Label="Path"; Expression={$_.ItemPath} },
@{Label="Version"; Expression={$_.Version}}
}
}
Close-Window
@gyusza
Copy link

gyusza commented Jun 16, 2017

Hey,
Im dabbling around with your PS, and i was wondering if you had a solution for only checking the latest version. Our web db only holds a single latest version of the items, so previous versions are not necessary in the comparison...

Thanks,
Gyula

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment