-
Notifications
You must be signed in to change notification settings - Fork 55
/
DSC_DnsServerRootHint.psm1
131 lines (101 loc) · 3.4 KB
/
DSC_DnsServerRootHint.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
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
$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common'
$script:dnsServerDscCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DnsServerDsc.Common'
Import-Module -Name $script:dscResourceCommonPath
Import-Module -Name $script:dnsServerDscCommonPath
$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
<#
.SYNOPSIS
Get desired state
.PARAMETER IsSingleInstance
Key for the resource. This value must be set to 'Yes'
#>
function Get-TargetResource
{
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[System.String]
$IsSingleInstance,
[Parameter(Mandatory = $true)]
[Microsoft.Management.Infrastructure.CimInstance[]]
[AllowEmptyCollection()]
$NameServer
)
Assert-Module -ModuleName 'DNSServer'
Write-Verbose -Message $script:localizedData.GettingCurrentRootHintsMessage
$result = @{
IsSingleInstance = 'Yes'
NameServer = Convert-RootHintsToHashtable -RootHints @(Get-DnsServerRootHint)
}
Write-Verbose -Message ($script:localizedData.FoundRootHintsMessage -f $result.NameServer.Count)
$result
}
<#
.SYNOPSIS
Set desired state
.PARAMETER IsSingleInstance
Key for the resource. This value must be set to 'Yes'
.PARAMETER NameServer
A list of names and IP addresses as a hashtable. This may look like this: NameServer = @{ 'rh1.vm.net.' = '20.1.1.1' }
#>
function Set-TargetResource
{
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[System.String]
$IsSingleInstance,
[Parameter(Mandatory = $true)]
[Microsoft.Management.Infrastructure.CimInstance[]]
[AllowEmptyCollection()]
$NameServer
)
Write-Verbose -Message $script:localizedData.RemovingAllRootHintsMessage
Get-DnsServerRootHint | Remove-DnsServerRootHint -Force
foreach ($item in $NameServer)
{
Write-Verbose -Message ($script:localizedData.AddingRootHintMessage -f $item.Key)
Add-DnsServerRootHint -NameServer $item.Key -IPAddress ($item.value -split ',' | ForEach-Object { $_.Trim() })
}
}
<#
.SYNOPSIS
Test desired state
.PARAMETER IsSingleInstance
Key for the resource. This value must be set to 'Yes'
.PARAMETER NameServer
A list of names and IP addresses as a hashtable. This may look like this: NameServer = @{ 'rh1.vm.net.' = '20.1.1.1' }
#>
function Test-TargetResource
{
[OutputType([Bool])]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[System.String]
$IsSingleInstance,
[Parameter(Mandatory = $true)]
[Microsoft.Management.Infrastructure.CimInstance[]]
[AllowEmptyCollection()]
$NameServer
)
Write-Verbose -Message $script:localizedData.ValidatingRootHintsMessage
$currentState = Get-TargetResource @PSBoundParameters
$desiredState = $PSBoundParameters
foreach ($entry in $desiredState.NameServer)
{
$entry.Value = $entry.Value -replace ' ', ''
}
$params = @{
CurrentValues = $currentState
DesiredValues = $desiredState
TurnOffTypeChecking = $true
ReverseCheck = $true
}
$result = Test-DscParameterState @params
$result
}