Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compare two indexes using Sitecore PowerShell Extensions to see what's missing.
# 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