Parsers/GPO/Audit.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
Function Write-GPOAuditOptionCSVData
{
    [CmdletBinding()]
    [OutputType([string])]
    param
    (
        [Parameter(Mandatory = $true)]
        [System.Object]$Entry
    )

    $Value = $Entry.'Inclusion Setting'
    $Name = $Entry.'Subcategory'.TrimStart("Option:")

    $retHash = @{}
    
    $rethash.Name = $Name
    $rethash.Value = $Value

    Write-DSCString -Resource -Name "AuditPolicyOption: $Name" -Type AuditPolicyOption -Parameters $rethash
}
Function Write-GPOAuditCSVData
{
    [CmdletBinding()]
    [OutputType([string])]
    param
    (
        [Parameter(Mandatory = $true)]
        [System.Object]$Entry
    )

    $retHash = @{}
    $GUID = $Entry.'Subcategory GUID'.TrimStart("{").TrimEnd("}")
    if (!$AuditSubcategoryHash.ContainsKey($GUID))
    {
        Write-Verbose "Write-GPOAuditCSVData:$GUID ($($Entry.Subcategory)) is no longer supported or not implemented"
        Add-ProcessingHistory -Type AuditPolicySubcategory -Name "EventAuditing(GPO) $($Entry.SubCategory)" -ParsingError
        return ""
    }

    $retHash.Name = $AuditSubCategoryHash[$GUID]
    $Name = $Entry.SubCategory

    switch -regex ($Entry."Inclusion Setting")
    {
        "Success and Failure"
        {
            $retHash.Ensure = "Present"
            $retHash.AuditFlag = "Success"
            $duplicate = $retHash.Clone()
            $duplicate.AuditFlag = "Failure"
            Write-DSCString -Resource -Name "$Name (Success) - Inclusion" -Type AuditPolicySubcategory -Parameters $retHash
            Write-DSCString -Resource -Name "$Name (Failure) - Inclusion" -Type AuditPolicySubcategory -Parameters $duplicate
        }

        "No Auditing"
        {
            $retHash.Ensure = "Absent"
            $retHash.AuditFlag = "Success"
            $duplicate = $retHash.Clone()
            $duplicate.AuditFlag = "Failure"
            Write-DSCString -Resource -Name "$Name (Success) - Inclusion" -Type AuditPolicySubcategory -Parameters $retHash
            $retHash.AuditFlag = "Failure"
            Write-DSCString -Resource -Name "$Name (Failure) - Inclusion" -Type AuditPolicySubcategory -Parameters $duplicate
        }

        "^Success$"
        {
            $retHash.Ensure = "Present"
            $retHash.AuditFlag = "Success"
            Write-DSCString -Resource -Name "$Name (Success) - Inclusion" -Type AuditPolicySubcategory -Parameters $retHash
            $duplicate = $retHash.Clone()
            $duplicate.AuditFlag = "Failure"
            $duplicate.Ensure = "Absent"
            Write-DSCString -Resource -Name "$Name (Failure) - Inclusion" -Type AuditPolicySubcategory -Parameters $duplicate
        }

        "^Failure$"
        {
            $retHash.Ensure = "Present"
            $retHash.AuditFlag = "Failure"
            Write-DSCString -Resource -Name "$Name (Failure) - Inclusion" -Type AuditPolicySubcategory -Parameters $retHash
            $duplicate = $retHash.Clone()
            $duplicate.AuditFlag = "Success"
            $duplicate.Ensure = "Absent"
            Write-DSCString -Resource -Name "$Name (Success) - Inclusion" -Type AuditPolicySubcategory -Parameters $duplicate
        }
    }
    
    $exclusionHash = $retHash.Clone()
    switch -regex ($Entry."Exclusion Setting")
    {
        "Success and Failure"
        {
            $exclusionHash.Ensure = "Absent"
            $exclusionHash.AuditFlag = "Success"
            $exclusionHashduplicate = $exclusionHash.Clone()
            $exclusionHashduplicate.AuditFlag = "Failure"
            Write-DSCString -Resource -Name "$Name (Success) - Exclusion" -Type AuditPolicySubcategory -Parameters $exclusionHash
            $retHash.AuditFlag = "Failure"
            Write-DSCString -Resource -Name "$Name (Failure) - Exclusion" -Type AuditPolicySubcategory -Parameters $exclusionHashduplicate
        }

        "No Auditing"
        {
            # I am not sure how to make sure that "No Auditing" is Excluded or ABSENT. What should it be set to then?
        }

        "^Failure$"
        {
            $exclusionHash.Ensure = "Absent"
            $exclusionHash.AuditFlag = $Entry."Exclusion Setting"
            Write-DSCString -Resource -Name "$Name - Exclusion" -Type AuditPolicySubcategory -Parameters $exclusionHash
        }

        "^Success$"
        {
            $exclusionHash.Ensure = "Absent"
            $exclusionHash.AuditFlag = $Entry."Exclusion Setting"
            Write-DSCString -Resource -Name "$Name - Exclusion" -Type AuditPolicySubcategory -Parameters $exclusionHash
        }
    }
}

Function Write-GPOAuditINFData
{
    [CmdletBinding()]
    [OutputType([String])]
    param
    (
        [Parameter(Mandatory = $true)]
        [string]$Key,

        [Parameter(Mandatory = $true)]
        [string]$AuditData
    ) 

    if (!$AuditCategoryHash.ContainsKey($key))
    {
        Write-Verbose "Write-INFAuditData:$Key is no longer supported or not implemented"
        Add-ProcessingHistory -Type AuditPolicySubcategory -Name "EventAuditing(INF) $($key)" -ParsingError
        return ""
    }

    $AuditFlag = "None", "Success", "Failure", "SuccessAndFailure", "None"

    foreach ($subCategory in $AuditCategoryHash[$key])
    {
        $paramHash = @{}
        $paramHash.Name = $subCategory
        switch -Regex ($AuditData)
        {
            "(0|4)" 
            { 
                $paramHash.AuditFlag = "Failure"
                $paramHash.Ensure = "Absent"
                Write-DSCString -Resource -Name "EventAuditing(INF): $($subCategory): NoAuditing(Failure)" -Type AuditPolicySubcategory -Parameters $paramHash 
                $paramHash.AuditFlag = "Success"
                $paramHash.Ensure = "Absent"
                Write-DSCString -Resource -Name "EventAuditing(INF): $($subCategory): NoAuditing(Success)" -Type AuditPolicySubcategory -Parameters $paramHash 
                return
            } 
            
            "1"
            {
                $paramHash.AuditFlag = "Success"
                Write-DSCString -Resource -Name "EventAuditing(INF): $($subCategory): Success" -Type AuditPolicySubcategory -Parameters $paramHash 
                $paramHash.AuditFlag = "Failure"
                $paramHash.Ensure = "Absent"
                Write-DSCString -Resource -Name "EventAuditing(INF): $($subCategory): Failure" -Type AuditPolicySubcategory -Parameters $paramHash 
            }

            "2"
            {
                $paramHash.AuditFlag = "Failure"
                Write-DSCString -Resource -Name "EventAuditing(INF): $($subCategory): Failure" -Type AuditPolicySubcategory -Parameters $paramHash 
                $paramHash.AuditFlag = "Success"
                $paramHash.Ensure = "Absent"
                Write-DSCString -Resource -Name "EventAuditing(INF): $($subCategory): Success" -Type AuditPolicySubcategory -Parameters $paramHash 
            }

            "3"
            {
                $paramHash.AuditFlag = "Failure"
                Write-DSCString -Resource -Name "EventAuditing(INF): $($subCategory): Failure" -Type AuditPolicySubcategory -Parameters $paramHash 
                $paramHash.AuditFlag = "Success"
                Write-DSCString -Resource -Name "EventAuditing(INF): $($subCategory): Success" -Type AuditPolicySubcategory -Parameters $paramHash 
            }

            Default 
            {
                Write-Verbose "Write-GPOAuditINFData: $_ is not supported"
                Add-ProcessingHistory -Type AuditPolicySubcategory -Name "EventAuditing(INF): $($key)" -ParsingError
            }
        }
    }
}