Parsers/ASC/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
Function Write-ASCAuditJSONData
{
    [CmdletBinding()]
    [OutputType([String])]
    param
    (
        [Parameter(Mandatory = $true)]
        $AuditData
    )

    if (!$AuditSubCategoryHash.ContainsKey($AuditData.AuditPolicyID))
    {
        Write-Warning "Cannot find Audit Policy for ($($AuditData.AuditPolicyID)) from ($($AuditData.Name))"
        return ""
    }
    else
    {
        $Category = $AuditSubCategoryHash[$AuditData.AuditPolicyID]
        $AuditData.ExpectedValue = ($AuditData.ExpectedValue -replace "Success And Failure", "SuccessAndFailure") -replace "No Auditing", "NoAuditing"
            
        $policyHash = @{}
        $policyHash.AuditFlag = $AuditData.ExpectedValue
        $policyHash.Name = $Category 
            
        switch ($policyHash.AuditFlag)
        {
            "SuccessAndFailure" 
            {
                $policyHash.Ensure = "Present"
                $policyHash.AuditFlag = "Success"
                $Duplicate = $policyHash.Clone()
                $Duplicate.AuditFlag = "Failure"
                Write-DSCString -Resource -Type AuditPolicySubCategory -Name "$($AuditData.CCEID): $($AuditData.ruleName) (Success)" -Parameters $policyHash -CommentOUT:($AuditData.State -ne 'Enabled') -DoubleQuoted
                Write-DSCString -Resource -Type AuditPolicySubCategory -Name "$($AuditData.CCEID): $($AuditData.ruleName) (Failure)" -Parameters $Duplicate -CommentOUT:($AuditData.State -ne 'Enabled') -DoubleQuoted
            }
            
            "NoAuditing" 
            {
                $policyHash.Ensure = "Absent"
                $policyHash.AuditFlag = "Success"
                $Duplicate = $policyHash.Clone()
                $Duplicate.AuditFlag = "Failure"
                Write-DSCString -Resource -Type AuditPolicySubcategory -Name "$($AuditData.CCEID): $($AuditData.ruleName) (Success)" -Parameters $policyHash -CommentOUT:($AuditData.State -ne 'Enabled') -DoubleQuoted
                Write-DSCString -Resource -Type AuditPolicySubcategory -Name "$($AuditData.CCEID): $($AuditData.ruleName) (Failure)" -Parameters $Duplicate -CommentOUT:($AuditData.State -ne 'Enabled') -DoubleQuoted
            } 

            Default
            {
                Write-DSCString -Resource -Type AuditPolicySubcategory -Name "$($AuditData.CCEID): $($AuditData.ruleName)" -Parameters $policyHash -CommentOUT:($AuditData.State -ne 'Enabled') -DoubleQuoted
            }
        }
    }
}