Skip to content

Commit

Permalink
Merge pull request #96 from 1800Zeta/DnsServerPolicies
Browse files Browse the repository at this point in the history
ResourceName: xDnsServerClientSubnets
  • Loading branch information
indented-automation authored Jul 23, 2019
2 parents 9e2789f + 1efd44c commit 581d1b0
Show file tree
Hide file tree
Showing 5 changed files with 559 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
# Localized messages
data LocalizedData
{
# culture="en-US"
ConvertFrom-StringData @'
GettingDnsServerClientSubnetMessage = Getting DNS Server Client Subnet '{0}'.
CreatingDnsServerClientSubnetMessage = Creating DNS Server Client Subnet '{0}' IPv4 '{1}' and/or IPv6 '{2}'.
UpdatingDnsServerClientSubnetMessage = Updating DNS Server Client Subnet '{0}' IPv4 '{1}' and/or IPv6 '{2}'.
RemovingDnsServerClientSubnetMessage = Removing DNS Server Client Subnet '{0}'.
NotDesiredPropertyMessage = DNS Server Client Subnet property '{0}' is not correct. Expected '{1}', actual '{2}'
InDesiredStateMessage = DNS Server Client Subnet '{0}' is in the desired state.
NotInDesiredStateMessage = DNS Server Client Subnet '{0}' is NOT in the desired state.
'@
}

<#
.SYNOPSIS
This will return the current state of the resource.
.PARAMETER Name
Specifies the name of the client subnet.
.PARAMETER IPv4Subnet
Specify an array (1 or more values) of IPv4 Subnet addresses in CIDR Notation.
.PARAMETER IPv6Subnet
Specify an array (1 or more values) of IPv6 Subnet addresses in CIDR Notation.
#>
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Name

)

Write-Verbose -Message ($LocalizedData.GettingDnsServerClientSubnetMessage -f $Name)
$record = Get-DnsServerClientSubnet -Name $Name -ErrorAction SilentlyContinue

if ($null -eq $record)
{
return @{
Name = $Name
IPv4Subnet = $null
IPv6Subnet = $null
Ensure = 'Absent'
}
}

return @{
Name = $record.Name
IPv4Subnet = $record.IPv4Subnet
IPv6Subnet = $record.IPv6Subnet
Ensure = 'Present'
}
} #end function Get-TargetResource

<#
.SYNOPSIS
This will configure the resource.
.PARAMETER Name
Specifies the name of the client subnet.
.PARAMETER IPv4Subnet
Specify an array (1 or more values) of IPv4 Subnet addresses in CIDR Notation.
.PARAMETER IPv6Subnet
Specify an array (1 or more values) of IPv6 Subnet addresses in CIDR Notation.
#>
function Set-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Name,

[Parameter()]
[System.String[]]
$IPv4Subnet,

[Parameter()]
[System.String[]]
$IPv6Subnet,

[Parameter()]
[ValidateSet('Present','Absent')]
[System.String]
$Ensure = 'Present'
)

$dnsServerClientSubnetParameters = @{ Name = $Name}
$clientSubnet = Get-DnsServerClientSubnet -Name $Name -ErrorAction SilentlyContinue
if ($Ensure -eq 'Present')
{
if ($IPv4Subnet)
{
$dnsServerClientSubnetParameters.Add('IPv4Subnet',$IPv4Subnet)
}
if ($IPv6Subnet)
{
$dnsServerClientSubnetParameters.Add('IPv6Subnet',$IPv6Subnet)
}

if ($clientSubnet)
{
$dnsServerClientSubnetParameters.Add('Action', "REPLACE")
Write-Verbose -Message ($LocalizedData.UpdatingDnsServerClientSubnetMessage -f $Name, "$IPv4Subnet", "$IPv6Subnet")
Set-DnsServerClientSubnet @dnsServerClientSubnetParameters
}
else
{
Write-Verbose -Message ($LocalizedData.CreatingDnsServerClientSubnetMessage -f $Name, "$IPv4Subnet", "$IPv6Subnet")
Add-DnsServerClientSubnet @dnsServerClientSubnetParameters
}
}
elseif ($Ensure -eq 'Absent')
{
Write-Verbose -Message ($LocalizedData.RemovingDnsServerClientSubnetMessage -f $Name)
Remove-DnsServerClientSubnet -Name $Name
}
} #end function Set-TargetResource

<#
.SYNOPSIS
This will return whether the resource is in desired state.
.PARAMETER Name
Specifies the name of the client subnet.
.PARAMETER IPv4Subnet
Specify an array (1 or more values) of IPv4 Subnet addresses in CIDR Notation.
.PARAMETER IPv6Subnet
Specify an array (1 or more values) of IPv6 Subnet addresses in CIDR Notation.
#>
function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Name,

[Parameter()]
[System.String[]]
$IPv4Subnet,

[Parameter()]
[System.String[]]
$IPv6Subnet,

[Parameter()]
[ValidateSet('Present','Absent')]
[System.String]
$Ensure = 'Present'
)

$result = Get-TargetResource -Name $Name

if ($Ensure -ne $result.Ensure)
{
Write-Verbose -Message ($LocalizedData.NotDesiredPropertyMessage -f 'Ensure', $Ensure, $result.Ensure)
Write-Verbose -Message ($LocalizedData.NotInDesiredStateMessage -f $Name)
return $false
}
elseif ($Ensure -eq 'Present')
{
$IPv4SubnetResult = $result.IPv4Subnet
$IPv6SubnetResult = $result.IPv6Subnet

if (($null -eq $IPv4Subnet) -and ($null -ne $IPv4SubnetResult))
{
Write-Verbose -Message ($LocalizedData.NotDesiredPropertyMessage -f 'IPv4Subnet', "$IPv4Subnet", "$IPv4SubnetResult")
Write-Verbose -Message ($LocalizedData.NotInDesiredStateMessage -f $Name)
return $false
}

if (($null -eq $IPv4SubnetResult) -and ($null -ne $IPv4Subnet))
{
Write-Verbose -Message ($LocalizedData.NotDesiredPropertyMessage -f 'IPv4Subnet', "$IPv4Subnet", "$IPv4SubnetResult")
Write-Verbose -Message ($LocalizedData.NotInDesiredStateMessage -f $Name)
return $false
}

if ($IPv4Subnet)
{
$IPv4Difference = Compare-Object -ReferenceObject $IPv4Subnet -DifferenceObject $IPv4SubnetResult
if ($IPv4Difference)
{
Write-Verbose -Message ($LocalizedData.NotDesiredPropertyMessage -f 'IPv4Subnet', "$IPv4Subnet", "$IPv4SubnetResult")
Write-Verbose -Message ($LocalizedData.NotInDesiredStateMessage -f $Name)
return $false
}
}

if (($null -eq $IPv6Subnet) -and ($null -ne $IPv6SubnetResult))
{
Write-Verbose -Message ($LocalizedData.NotDesiredPropertyMessage -f 'IPv6Subnet', "$IPv6Subnet", "$IPv6SubnetResult")
Write-Verbose -Message ($LocalizedData.NotInDesiredStateMessage -f $Name)
return $false
}

if (($null -eq $IPv6SubnetResult) -and ($null -ne $IPv6Subnet))
{
Write-Verbose -Message ($LocalizedData.NotDesiredPropertyMessage -f 'IPv6Subnet', "$IPv6Subnet", "$IPv6SubnetResult")
Write-Verbose -Message ($LocalizedData.NotInDesiredStateMessage -f $Name)
return $false
}

if ($IPv6Subnet)
{
$IPv6Difference = Compare-Object -ReferenceObject $IPv6Subnet -DifferenceObject $IPv6SubnetResult
if ($IPv6Difference)
{
Write-Verbose -Message ($LocalizedData.NotDesiredPropertyMessage -f 'IPv6Subnet', "$IPv6Subnet", "$IPv6SubnetResult")
Write-Verbose -Message ($LocalizedData.NotInDesiredStateMessage -f $Name)
return $false
}
}
}
Write-Verbose -Message ($LocalizedData.InDesiredStateMessage -f $Name)
return $true
} #end function Test-TargetResource

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[ClassVersion("1.0.0.0"), FriendlyName("xDnsServerClientSubnet")]
class MSFT_xDnsServerClientSubnet : OMI_BaseResource
{
[Key, Description("Specifies the name of the client subnet.")] string Name;
[Write, Description("Specify an array (1 or more values) of IPv4 Subnet addresses in CIDR Notation.")] string IPv4Subnet[];
[Write, Description("Specify an array (1 or more values) of IPv6 Subnet addresses in CIDR Notation.")] string IPv6Subnet[];
[Write, Description("Should this DNS server client subnet be present or absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
};

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
* **xDnsRecord** This resource allows for the creation of IPv4 host (A) records, CNames, or PTRs against a specific zone on the DNS server.
* **xDnsServerSetting** This resource manages the DNS sever settings/properties.
* **xDnsServerDiagnostics** This resource manages the DNS server diagnostic settings/properties.
* **xDnsServerClientSubnet** This resource manages the DNS Client Subnets that are used in DNS Policies.

### xDnsServerForwarder

Expand Down Expand Up @@ -204,6 +205,15 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
* **UseSystemEventLog**: Specifies whether the DNS server uses the system event log for logging.
* **WriteThrough**: Specifies whether the DNS server logs write-throughs.

### xDnsServerClientSubnet

Requires Windows Server 2016 onwards

* **Name**: Specifies the name of the client subnet.
* **IPv4Subnet**: Specify an array (1 or more values) of IPv4 Subnet addresses in CIDR Notation.
* **IPv6Subnet**: Specify an array (1 of more values) of IPv6 Subnet addresses in CIDR Notation.
* **Ensure**: Whether the client subnet should be present or removed

### xDnsServerRootHint

* **IsSingleInstance**: Specifies the resource is a single instance, the value must be 'Yes'
Expand All @@ -218,6 +228,7 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
* Copied enhancements to Test-DscParameterState from NetworkingDsc
* Put the helper module to its own folder
* Added xDnsServerRootHint resource
* Added xDnsServerClientSubnet resource

### 1.13.0.0

Expand Down
Loading

0 comments on commit 581d1b0

Please sign in to comment.