Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Last active July 16, 2019 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save IISResetMe/57ce7b76e1001974a4f7170e10775875 to your computer and use it in GitHub Desktop.
Save IISResetMe/57ce7b76e1001974a4f7170e10775875 to your computer and use it in GitHub Desktop.
function Compare-Array
{
param(
[array]$Ref,
[array]$Diff
)
$max = [math]::Max($Ref.Length,$Diff.Length)
for($i = 0; $i -lt $max; $i++){
if($Ref[$i] -ne $Diff[$i]){
[pscustomobject]@{
Index = $i
Left = $Ref[$i]
Right = $Diff[$i]
}
}
}
}
function Compare-StringSet
{
param(
[string[]]$Ref,
[string[]]$Diff,
[switch]$CaseSensitive
)
$Comparer = if($CaseSensitive){
[System.StringComparer]::InvariantCulture
}
else {
[System.StringComparer]::InvariantCultureIgnoreCase
}
$Results = [ordered]@{
Left = @()
Both = @()
Right = @()
}
$temp = [System.Collections.Generic.HashSet[string]]::new($Ref, $Comparer)
$temp.IntersectWith($Diff)
$Results['Both'] = $temp
$temp = [System.Collections.Generic.HashSet[string]]::new($Ref,[System.StringComparer]::CurrentCultureIgnoreCase)
$temp.ExceptWith($Diff)
$Results['Left'] = $temp
$temp = [System.Collections.Generic.HashSet[string]]::new($Diff,[System.StringComparer]::CurrentCultureIgnoreCase)
$temp.ExceptWith($Ref)
$Results['Right'] = $temp
return [pscustomobject]$Results
}
@fatherjack
Copy link

Fabulous!

Many thanks
J

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment