-1

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

  • What have you tried so far? Can you post an example of your code attempt(s)? – Dan Sinclair Jan 7 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. – user1621791 Jan 7 at 12:43
  • 2
    The objects have a property called Version. – Michael West Jan 7 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 ! – user1621791 Jan 7 at 13:25
  • 5
    @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 at 14:01
1

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
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.