Created
November 29, 2020 13:53
-
-
Save martinrayenglish/73b2dd30423426a6a56406e8a068e83b to your computer and use it in GitHub Desktop.
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
<# | |
.SYNOPSIS | |
NOTE: Check for items in the selected target database that are missing from selected index, and output downloadable report | |
#> | |
$missingFromIndexList = [System.Collections.ArrayList]@() | |
$startDatabase = "master" | |
$root = Get-Item -Path "$($startDatabase):\content" | |
filter IndexCheck { | |
param( | |
[Parameter(Mandatory=$true, ValueFromPipeline=$true)] | |
$Item, | |
[Parameter(Mandatory=$true)] | |
$Index | |
) | |
Process { | |
$templateCheck = [Sitecore.Data.Managers.TemplateManager]::GetTemplate($Item) | |
if ($null -ne $templateCheck) { | |
$criteria = @(@{Filter = "Equals"; Field = "_fullpath"; Value = $Item.Paths.Path}) | |
$items = Find-Item -Index $Index -Criteria $criteria | Initialize-Item | |
If ($items.Length -eq 0) { | |
Write-Host("Item Missing From $($Index) Index: $($Item.Paths.Path) ") -ForegroundColor Red | |
return $Item | |
} | |
} | |
} | |
} | |
Function Get-OptionsObjects{ | |
param($getType) | |
$targetObject = $null | |
$targetObjectHash = @{} | |
switch ($getType) | |
{ | |
"index" { | |
$targetObject = Get-SearchIndex | |
} | |
"db" { | |
$targetObject = Get-Database | |
} | |
} | |
$targetObject | ForEach-Object{ | |
$targetObjectHash.Add($_.Name, $_.Name) > $null | |
} | |
return $targetObjectHash | |
} | |
$props = @{ | |
Parameters = @( | |
@{ | |
Name="root" | |
Title="Choose the start root" | |
Tooltip="Only items from this root will be used in comparison" | |
} | |
@{ | |
Name = "contentDatabase" | |
Title = "Please select the content database" | |
Tooltip = "The content database to use when performing item check" | |
Options = Get-OptionsObjects "db" | |
} | |
@{ | |
Name = "searchIndex" | |
Title = "Please select the search index" | |
Tooltip = "The search index to use when performing item check" | |
Options = Get-OptionsObjects "index" | |
} | |
) | |
Title = "Content Item Index Check" | |
Description = "Check for items in database that are missing from index" | |
OkButtonName = "Proceed" | |
CancelButtonName = "Abort" | |
ShowHints = $true | |
} | |
$checkValue = Read-Variable @props | |
if($checkValue -ne "ok") { | |
Exit | |
} | |
if((show-confirm "Confirm to check for all items in the $($contentDatabase) database that are missing from the $($searchIndex) index?")-eq "yes") { | |
$stopwatch = [system.diagnostics.stopwatch]::StartNew() | |
$targetRootItem = Get-Item -Path "$($contentDatabase):" -ID $root.Id | |
Write-Host("Searching $($targetRootItem.Paths.Path) for items missing from the $($searchIndex) index...") | |
$missingFromIndexList = Get-ChildItem -Recurse -Item $targetRootItem | IndexCheck -Index $searchIndex | |
$stopwatch.Stop() | |
Write-Host("Searching $($targetRootItem.Paths.Path) completed in $($stopwatch.Elapsed.ToString('hh\:mm\:ss')). $($missingFromIndexList.Count) items missing in the $($targetIndex) index.") | |
if ($null -eq $missingFromIndexList){ | |
Write-Host "No missing items in $($searchIndex) index!" -ForegroundColor Green | |
exit | |
} | |
$missingFromIndexList | Show-ListView -Modal -Title "Content items in $($contentDatabase) database missing from $($searchIndex) index" -Property @{Label="Name"; Expression={$_.DisplayName}}, @{Label="Path"; Expression={$_.Paths.Path}}, @{Label="Id"; Expression={$_.Id}}, @{Label="Updated"; Expression={$_.__Updated}}, @{Label="Updated By"; Expression={$_."__Updated By"}} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment