Parsers/GPO/INI.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
Function Write-GPOIniFileXMLData
{
    [OutputType([string])]
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [System.Xml.XmlElement]$XML  
    )

    $Properties = $XML.Properties
    
    $iniHash = @{}
    $iniHash.Path = $Properties.Path
    switch -regex ($Properties.Action)
    {
        "(C|R|U)"
        {
            $iniHash.Name = $Properties.Property
            $iniHash.Value = $Properties.Value
            $iniHash.Section = $Properties.Section
            $iniHash.Ensure = "Present"
        }

        "(R|U)"
        {
            $iniHash.Force = $true
        }

        "D"
        {
            if ($XML.Property -ne $null)
            {
                $iniHash.Name = $Properties.Property
            }

            if ($XML.Section -ne $null)
            {
                $iniHash.Section = $Properties.Section
            }

            if ($XML.Value -ne $null)
            {
                $iniHash.Value = $Properties.Value
            }

            $iniHash.Ensure = "Absent"
        }

    }

    Write-DSCString -Resource -Type Carbon_IniFile -Name "IniFile(XML): $($iniHash.Path)" -Parameters $iniHash
}