Private/Compare-HPSSecurityPolicy.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
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
Function Compare-HPSSecurityPolicy {

    <#
        .SYNOPSIS
        n/a

        .DESCRIPTION
        n/a

        .PARAMETER ReferenceObject
        n/a

        .PARAMETER DifferenceObject
        n/a

        .PARAMETER Detail
        n/a

        .EXAMPLE
        Compare-HPSSecurityPolicy -ReferenceObject $ReferenceObject -DifferenceObject $DifferenceObject

        .INPUTS
        System.Object

        .OUTPUTS
        System.Object

        .LINK
        https://hardening.thomas-illiet.fr/Private/Compare-HPSSecurityPolicy/

        .LINK
        https://github.com/thomas-illiet/Hardening/blob/stable/Hardening/Private/Compare-HPSSecurityPolicy/.ps1

        .NOTES
        - File Name : Compare-HPSSecurityPolicy.ps1
        - Author : Thomas ILLIET
    #>


    [CmdletBinding( HelpUri = "https://hardening.thomas-illiet.fr/Private/Compare-HPSSecurityPolicy/" )]
    [OutputType( [System.Object] )]
    Param (
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [System.Object]
        $ReferenceObject,

        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [System.Object]
        $DifferenceObject,

        [Parameter()]
        [System.boolean]
        $Detail = $false
    )

    begin {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"
    }

    process {
        $CompareResult = Compare-Object -ReferenceObject $ReferenceObject -DifferenceObject $DifferenceObject -Property 'Name', 'Value' -IncludeEqual
        if ( $Detail -eq $False ) {
            if ( ( $CompareResult | Where-Object {$_.SideIndicator -eq '<='} ).count -eq 0 ) {
                return $true
            }
            else {
                return $false
            }
        }
        else {
            return $CompareResult | Where-Object { ( $_.SideIndicator -eq '<=' ) -or ( $_.SideIndicator -eq '==' ) }
        }
    }

    end {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete"
    }
}