DSCResources/ooNetwork/ooNetwork.schema.psm1

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
Configuration ooNetwork {
    param (
        [Parameter(Mandatory)]
        $Node
    )
    Import-DscResource -ModuleName NetworkingDsc -ModuleVersion 7.0.0.0

    if ($node.ContainsKey('Network')) {
        for ($i = 0; $i -lt $node.Network.Count; $i++) {
            $network = $node.Network[$i]

            NetAdapterName "Rename$($network.NetAdapterName)" {
                NewName    = $network.NetAdapterName
                MacAddress = $node.Lability_MACAddress[$i].Replace(':', '-')
            }

            if ($network.ContainsKey('IPAddress')) {
                IPAddress "SetIPAddress$($network.NetAdapterName)" {
                    AddressFamily  = 'IPv4'
                    InterfaceAlias = $network.NetAdapterName
                    IPAddress      = $network.IPAddress
                    DependsOn      = "[NetAdapterName]Rename$($network.NetAdapterName)"
                }
            }

            if ($network.ContainsKey('DefaultGatewayAddress')) {
                DefaultGatewayAddress "SetDefaultGatewayAddress$($network.NetAdapterName)" {
                    AddressFamily  = 'IPv4'
                    InterfaceAlias = $network.NetAdapterName
                    Address        = $network.DefaultGatewayAddress
                    DependsOn      = "[NetAdapterName]Rename$($network.NetAdapterName)"
                }
            }

            <#
                If Address isn't specified the adapter is changed to DHCP. I noticed
                some adapters will default to 127.0.0.1 for reasons unknown unless
                they are forced to DHCP like this.
            #>

            if ($network.ContainsKey('DnsServerAddress')) {
                DnsServerAddress "SetDnsServerAddress$($network.NetAdapterName)" {
                    AddressFamily  = 'IPv4'
                    InterfaceAlias = $network.NetAdapterName
                    Address        = $network.DnsServerAddress
                    DependsOn      = "[NetAdapterName]Rename$($network.NetAdapterName)"
                }
            } else {
                DnsServerAddress "SetDnsServerAddress$($network.NetAdapterName)" {
                    AddressFamily  = 'IPv4'
                    InterfaceAlias = $network.NetAdapterName
                    DependsOn      = "[NetAdapterName]Rename$($network.NetAdapterName)"
                }
            }

            DnsConnectionSuffix "SetDnsConnectionSuffix$($network.NetAdapterName)" {
                InterfaceAlias           = $network.NetAdapterName
                ConnectionSpecificSuffix = $node.FullyQualifiedDomainName
                DependsOn                = "[NetAdapterName]Rename$($network.NetAdapterName)"
            }
        }
    }
}