Environment: Sitecore 9.2 & SXA 1.9
Scenario: I have two different items and I would like to compare them and copy the missing children from one item to another using Powershell script.
Item A (
DifferenceObject
) - If empty copy all the children from Item B and if few children are missing then copy them from Item B without disturbing the other children of Item A.Item B (
ReferenceObject
) - This item can have grandchildren as well.
This is the script that I am using but while running this script on the same item twice, it is making duplicate copies of children instead of ignoring them.
$itemA = Get-ChildItem -Path "/sitecore/home/itemA"
$itemB = Get-ChildItem -Path "/sitecore/home/itemB"
$diffs = Compare-Object -ReferenceObject $itemB -DifferenceObject $itemA |
Where-Object { $_.SideIndicator -eq "<=" } | Select-Object -ExpandProperty InputObject
$diffs | Copy-Item -Destination $itemA.ID -Recurse
How to achieve this functionality? Thanks.
Compare-Object
function, while I running the script twice on for the same item it is making duplicate copies instead of ignoring them.