Public/Test-HPSAccountPolicy.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
Function Test-HPSAccountPolicy {

    <#
        .SYNOPSIS
        n/a

        .DESCRIPTION
        n/a

        .PARAMETER Enforce_Password_History
        n/a

        .PARAMETER Maximum_Password_Age
        n/a

        .PARAMETER Minimum_Password_Age
        n/a

        .PARAMETER Minimum_Password_Length
        n/a

        .PARAMETER Password_Must_Meet_Complexity_Requirements
        n/a

        .PARAMETER Store_Passwords_Using_Reversible_Encryption
        n/a

        .PARAMETER Account_Lockout_Duration
        n/a

        .PARAMETER Account_Lockout_Threshold
        n/a

        .PARAMETER Reset_Account_Lockout_Counter_After
        n/a

        .PARAMETER Enforce_User_Logon_Restrictions
        n/a

        .PARAMETER Maximum_Lifetime_For_Service_Ticket
        n/a

        .PARAMETER Maximum_Lifetime_For_User_Ticket
        n/a

        .PARAMETER Maximum_Lifetime_For_User_Ticket_Renewal
        n/a

        .PARAMETER Maximum_Tolerance_For_Computer_Clock_Synchronization
        n/a

        .PARAMETER Preset
        n/a

        .PARAMETER Type
        n/a

        .PARAMETER Cache
        n/a

        .PARAMETER Detail
        n/a

        .EXAMPLE
        Test-HPSAccountPolicy -Preset CIS_Windows_10

        .EXAMPLE
        Test-HPSAccountPolicy -Enforce_Password_History 24

        .EXAMPLE
        Test-HPSAccountPolicy -Enforce_Password_History 42 -Maximum_Password_Age 42

        .EXAMPLE
        Test-HPSAccountPolicy -Preset CIS_Windows_10 -Detail

        .EXAMPLE
        Test-HPSAccountPolicy -Enforce_Password_History 24 -Detail

        .OUTPUTS
        System.Boolean

        .OUTPUTS
        System.Array

        .LINK
        https://hardening.thomas-illiet.fr/Public/Test-HPSAccountPolicy/

        .LINK
        https://github.com/thomas-illiet/Hardening/blob/stable/Hardening/Public/Test-HPSAccountPolicy.ps1

        .NOTES
        - File Name : Test-HPSAccountPolicy.ps1
        - Author : Thomas ILLIET
    #>


    [CmdletBinding( DefaultParameterSetName = 'Custom', HelpUri = "https://hardening.thomas-illiet.fr/Public/Test-HPSAccountPolicy/" )]
    [OutputType( [System.Boolean] )]
    [OutputType( [System.Array] )]
    Param(
        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Enforce_Password_History,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Maximum_Password_Age,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Minimum_Password_Age,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Minimum_Password_Length,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Boolean]
        $Password_Must_Meet_Complexity_Requirements,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Boolean]
        $Store_Passwords_Using_Reversible_Encryption,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Account_Lockout_Duration,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Account_Lockout_Threshold,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Reset_Account_Lockout_Counter_After,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Enforce_User_Logon_Restrictions,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Maximum_Lifetime_For_Service_Ticket,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Maximum_Lifetime_For_User_Ticket,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Maximum_Lifetime_For_User_Ticket_Renewal,

        [Parameter( ParameterSetName = "Custom" )]
        [ValidateNotNullOrEmpty()]
        [System.Int32]
        $Maximum_Tolerance_For_Computer_Clock_Synchronization,

        [Parameter( ParameterSetName = "Preset" )]
        [ValidateNotNullOrEmpty()]
        [System.String]
        $Preset,

        [Parameter()]
        [ValidateSet('Local', 'Gpo')]
        [System.String]
        $Type = 'Local',

        [Parameter()]
        [System.Boolean]
        $Cache = $false,

        [Parameter()]
        [Switch]
        $Detail = $false
    )

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

    process {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)"

        # Obtain security policy parameters
        $Params= @{
            BoundParameters = $PsBoundParameters
            ParameterSetName = $PsCmdlet.ParameterSetName
            ConfigName = 'AccountPolicy'
        }
        $Parameters = Get-HPSSecurityPolicyParameters @Params

        # Get the current security configuration
        $Configuration = Get-HPSSecurityPolicy -ConfigName 'AccountPolicy' -Type $Type

        # Compare the security policy to obtain the status
        Compare-HPSSecurityPolicy -ReferenceObject $Parameters -DifferenceObject $Configuration -Detail $Detail
    }

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