-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathDiff-Objects.ps1
More file actions
88 lines (73 loc) · 2.25 KB
/
Diff-Objects.ps1
File metadata and controls
88 lines (73 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<#
.SYNOPSIS
Used to Compare two powershell objects
.DESCRIPTION
This compares two powershell objects by determining their shared
keys or array sizes and comparing the values of each. It uses the
Display-Object cmdlet for the heavy lifting
.PARAMETER Ref
The source object
.PARAMETER diff
The target object
.PARAMETER Avoid
a list of any object you wish to avoid comparing
.PARAMETER Parent
Only used for recursion
.PARAMETER Depth
The depth to which you wish to recurse
.PARAMETER NullAndBlankSame
Do we regard null and Blank the same for the purpose of comparisons.
.PARAMETER $ReportNodes
Do you wish to report on nodes containing objects as well as values?
.NOTES
Additional information about the function.
#>
function Diff-Objects
{
param
(
[Parameter(Mandatory = $true,
Position = 1)]
[object]$Ref,
[Parameter(Mandatory = $true,
Position = 2)]
[object]$Diff,
[Parameter(Mandatory = $false,
Position = 3)]
[object[]]$Avoid = @('Metadata', '#comment'),
[Parameter(Mandatory = $false,
Position = 4)]
[string]$Parent = '$',
[Parameter(Mandatory = $false,
Position = 5)]
[string]$NullAndBlankSame = $true,
[Parameter(Mandatory = $false,
Position = 6)]
[int]$ReportNodes = $true,
[Parameter(Mandatory = $false,
Position = 7)]
[int]$Depth =10
)
$Left = display-object $Ref -Avoid $Avoid -Parent $Parent -Depth $Depth -reportNodes $ReportNodes
$right = display-object $Diff -Avoid $Avoid -Parent $Parent -depth $Depth -reportNodes $ReportNodes
$Paths = $Left + $Right | Select path -Unique
$Paths | foreach{
$ThePath = $_.Path;
$Lvalue = $Left | where { $_.Path -eq $ThePath } | Foreach{ $_.Value };
$Rvalue = $Right | where { $_.Path -eq $ThePath } | Foreach{ $_.Value };
if ($RValue -eq $Lvalue)
{ $equality = '==' }
elseif ([string]::IsNullOrEmpty($Lvalue) -and
[string]::IsNullOrEmpty($rvalue) -and
$NullAndBlankSame)
{$equality = '=='}
else
{
$equality = "$(if ($lvalue -eq $null) { '-' }
else { '<' })$(if ($Rvalue -eq $null) { '-' }
else { '>' })"
}
[pscustomobject]@{ 'Ref' = $ThePath; 'Source' = $Lvalue; 'Target' = $Rvalue; 'Match' = $Equality }
}
}