1

Can Anyone help writing a PS script to get the item list where the latest version on web db is different than master

5
  • What have you tried so far? Can you post an example of your code attempt(s)? Jan 7, 2019 at 12:25
  • I am able to get all the child items and loop through the items to get the web and master db version of the file. I am not able to get the version of individual items. Jan 7, 2019 at 12:43
  • 2
    The objects have a property called Version. Jan 7, 2019 at 12:53
  • @MichaelWest : I got it while debugging, I am very new to power-shell. Thanks for your help !! I have prepared the script ! Jan 7, 2019 at 13:25
  • 7
    @user1621791 if you have an answer, please post it as an answer here so that others may benefit from it in the future.
    – Richard Seal
    Jan 7, 2019 at 14:01

2 Answers 2

3

As Richard Seal mentioned, the answer may benefit others in future who refer this question.

$masterdatabase = "master"
$webdatabase = "web"
$root = Get-Item -Path (@{$true="$($masterdatabase):\content\home"; $false="$($masterdatabase):\content"}[(Test-Path -Path "$($masterdatabase):\content\home")])


$props = @{
    Parameters = @(
        @{Name="root"; Title="Choose the report root"; Tooltip="Only items from this root will be returned."; }
            )
    Title = "comparison Report"
    Description = "Choose the criteria for the report."
    Width = 550
    Height = 300
    ShowHints = $true
    Icon = [regex]::Replace($PSScript.Appearance.Icon, "Office", "OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
}

$result = Read-Variable @props

if($result -eq "cancel") {
    exit
}

filter Where-comparereport {
    param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [Sitecore.Data.Items.Item]$item
    )

    if ($item) {
        $masteritem = $item.Versions.GetLatestVersion().Statistics.Revision

        $webitem = [Sitecore.Data.Database]::GetDatabase($webdatabase).GetItem($item.Id)
        if($webitem){

        $webitemnumber = $webitem.Versions.GetLatestVersion().Statistics.Revision

        if (!$masteritem.Equals($webitemnumber)) {
            $item
        }
        }
    }
}

$items = @($root) + @(($root.Axes.GetDescendants() | Initialize-Item)) | Where-comparereport

if($items.Count -eq 0) {
    Show-Alert "There are no content items that is different from web and master database"
} else {
    $props = @{
        Title = "Item versions difference Report"
        InfoTitle = "Items that the latest version on web db is different than master"
        InfoDescription = "Items that the latest version on web db is different than master"
        PageSize = 25
    }

    $items |
        Show-ListView @props -Property @{Label="Icon"; Expression={$_.__Icon} },
            @{Label="Name"; Expression={$_.DisplayName} },
            @{Label="Updated"; Expression={$_.__Updated} },
            @{Label="Updated by"; Expression={$_."__Updated by"} },
            @{Label="Created"; Expression={$_.__Created} },
            @{Label="Created by"; Expression={$_."__Created by"} },
            @{Label="Path"; Expression={$_.ItemPath} }
}

Close-Window
2
  • Could someone explain to me what line 3 is doing, please? Dec 30, 2020 at 22:54
  • Ok it checks if sitecore/content/Home path exists, if so it uses that as the root, if not, it uses sitecore/content as the root. Dec 30, 2020 at 22:59
0

I've created a button in the ribbon to check items that are different, and to do so I've made a little change to the very first line, now I can click on any item and have a report of all children that needs to be published

$currentItemPath = get-location
$masterdatabase = "master"
$webdatabase = "web"
$root = Get-Item -Path (@{$true="$currentItemPath"; $false="$($masterdatabase):\content"}
[(Test-Path -Path "$currentItemPath")])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.