Last active
October 22, 2020 15:10
-
-
Save michaellwest/4cc0d0da7889f50af745ae5331e83a02 to your computer and use it in GitHub Desktop.
Compare two indexes using Sitecore PowerShell Extensions to see what's missing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a ScopeQuery item found in SXA. You don't have to use this. | |
$scopeItem = Get-Item -Path "master:" -ID "{648F4C3A-C9EA-4FCF-82A3-39ED2AC90A06}" | |
# If not using SXA, you can replace this with the string from the QueryBuilder field type. | |
$scopeQuery = $scopeItem.ScopeQuery | |
$props = @{ | |
Index = "sitecore_sxa_master_index" | |
ScopeQuery = $scopeQuery | |
} | |
$referenceList = Find-Item @props | |
$referenceLookup = @{} | |
foreach($entry in $referenceList) { | |
$referenceLookup[$entry.ItemId.ToString()] = $entry | |
} | |
$props = @{ | |
Index = "sitecore_sxa_web_index" | |
ScopeQuery = $scopeQuery | |
} | |
$differenceList = Find-Item @props | |
$referenceIds = [System.Collections.Generic.List[string]]@() | |
$referenceList | ForEach-Object { $referenceIds.Add($_.ItemId) > $null } | |
$differenceIds = [System.Collections.Generic.List[string]]@() | |
$differenceList | ForEach-Object { $differenceIds.Add($_.ItemId) > $null } | |
$referenceHash = New-Object 'System.Collections.Generic.HashSet[String]' | |
$referenceHash.UnionWith($referenceIds) | |
$differenceHash = New-Object 'System.Collections.Generic.HashSet[String]' | |
$differenceHash.UnionWith($differenceIds) | |
$leftOnlyHash = New-Object 'System.Collections.Generic.HashSet[String]'($referenceHash) | |
$leftOnlyHash.ExceptWith($differenceHash) | |
$missing = $leftOnlyHash | ForEach-Object { $referenceLookup[$_] } | |
$missing | Select-Object -Property Path | Sort-Object -Property Path | Show-ListView | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment