Export/Private/Compare-Hashtables.ps1

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
Function Global:Compare-Hashtables {
    [CmdletBinding()]
    [OutputType([boolean])]
    <#
    .SYNOPSIS
        ...
    .DESCRIPTION
        ...
    #>

    param(
        [Parameter(Mandatory = $true)]
        [Hashtable]
        $HashtableA,
        [Parameter(Mandatory = $true)]
        [Hashtable]
        $HashtableB
    )
    process{
        foreach($pairA in $HashtableA.GetEnumerator()){
            if (-not($HashtableB.ContainsKey($pairA.Key))){
                $false
                return
            } else {
                if ($HashtableB[$pairA.Key] -ne $pairA.Value){
                    $false
                    return
                }
            }
        }
        foreach($pairB in $HashtableB.GetEnumerator()){
            if (-not($HashtableA.ContainsKey($pairB.Key))){
                $false
                return
            } else {
                if ($HashtableA[$pairB.Key] -ne $pairB.Value){
                    $false
                    return
                }
            }
        }
        $true
    }
}