Skip to content

Instantly share code, notes, and snippets.

@Mitya88
Created October 22, 2020 16:50
Show Gist options
  • Save Mitya88/f78b0881e42ba6c9eca4dca96669fef4 to your computer and use it in GitHub Desktop.
Save Mitya88/f78b0881e42ba6c9eca4dca96669fef4 to your computer and use it in GitHub Desktop.
function ExecuteHealthcheck {
param(
$componentId,
[hashtable]$params
)
$result = @{ }
$props = @{
Index = $params["SourceIndex"]
ScopeQuery = $params["Query"]
}
$referenceList = Find-Item @props
$referenceLookup = @{}
foreach($entry in $referenceList) {
$referenceLookup[$entry.ItemId.ToString()] = $entry
}
$props = @{
Index = $params["TargetIndex"]
ScopeQuery = $params["Query"]
}
$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[$_] }
if($missing.Count -gt 0){
$result["Status"] = "Error"
$result["Reason"] = "There are " + $missing.Count.ToString() + " differences between "+$params["SourceIndex"] + " and "+$params["TargetIndex"]
}
else{
$result["Status"] = "Healthy"
$result["HealthyMessage"] = "There is no differences"
}
return $result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment