Parsers/GPO/SecuritySettings.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

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

        [Parameter(Mandatory = $true)]
        [string]$SecurityData
    )
           
    $SecurityData = $SecurityData.Trim()
    $CommentOut = $false
    if ($Key -notin $SecuritySettings)
    {
        Write-Verbose "Write-InfSecuritySettingData:$Key is no longer supported or is not implemented"
        Add-ProcessingHistory -Type SecuritySetting -Name "SecuritySetting(INF): $Key" -ParsingError
        return ""
    }

    [int]$ValueData = 1
    if (![int]::TryParse($SecurityData, [ref]$ValueData))
    {
        [string]$ValueData = $SecurityData
    }
    elseif ($ValueData -eq -1)
    {
        Write-Verbose "Write-GPONewSecuritySettingData:$Key is set to -1 which means 'Not Configured'"
        Add-ProcessingHistory -Type SecurityOption -Name "SecuritySetting(INF): $Key" -Disabled
        $CommentOut = $true
    }

    $params = @{$key = $ValueData; Name = $Key}
    Write-DSCString -Resource -Name "SecuritySetting(INF): $Key" -Type SecuritySetting -Parameters $params -CommentOut:$CommentOut
}
Function Write-GPONewSecuritySettingINFData
{
    [CmdletBinding()]
    [OutputType([String])]
    param
    (
        [Parameter(Mandatory = $true)]
        [string]$Key,

        [Parameter(Mandatory = $true)]
        [string]$SecurityData
    )
           
    $SecurityData = $SecurityData.Trim()
    $ResourceName = $SecuritySetting = ""
    $CommentOut = $false
    if ($SecurityOptionSettings.ContainsKey($Key))
    {
        $SecuritySetting = $SecurityOptionSettings[$key]
        $ResourceName = "SecurityOption"
    }
    elseif ($AccountPolicySettings.ContainsKey($Key))
    {
        $ResourceName = "AccountPolicy"
        $SecuritySetting = $AccountPolicySettings[$key]
    }
    else
    {
        Write-Verbose "Write-GPONewSecuritySettingData:$Key is no longer supported or is not implemented"
        Add-ProcessingHistory -Type SecurityOption -Name "SecuritySetting(INF): $Key" -ParsingError
        return ""
    }

    [int]$ValueData = 1
    if (![int]::TryParse($SecurityData, [ref]$ValueData))
    {
        [string]$ValueData = $SecurityData
    }
    elseif ($ValueData -eq -1)
    {
        Write-Verbose "Write-GPONewSecuritySettingData:$Key is set to -1 which means 'Not Configured'"
        Add-ProcessingHistory -Type SecurityOption -Name "SecuritySetting(INF): $Key" -Disabled
        $CommentOut = $true
    }
    else
    {
        if ($SecuritySetting -in $SecuritySettingsWEnabledDisabled)
        {
            [string]$ValueData = $EnabledDisabled[$ValueData]
        }
    }

    $params = @{$SecuritySetting = $ValueData;Name = $SecuritySetting}
    Write-DSCString -Resource -Name "SecuritySetting(INF): $Key" -Type $ResourceName -Parameters $params -CommentOut:$CommentOut
}