Skip to content

Commit

Permalink
Merge pull request #76 from PowerShell/dev
Browse files Browse the repository at this point in the history
Release of version 1.11.0.0 of xDnsServer
  • Loading branch information
kwirkykat authored Jun 13, 2018
2 parents 3ea67af + 1262d5d commit e2a372a
Show file tree
Hide file tree
Showing 10 changed files with 857 additions and 198 deletions.
85 changes: 81 additions & 4 deletions DSCResources/MSFT_xDnsRecord/MSFT_xDnsRecord.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,28 @@ data LocalizedData
'@
}

<#
.SYNOPSIS
This will return the current state of the resource.
.PARAMETER Name
Specifies the name of the DNS server resource record object.
.PARAMETER Zone
Specifies the name of a DNS zone.
.PARAMETER Type
Specifies the type of DNS record.
.PARAMETER Target
Specifies the Target Hostname or IP Address.
.PARAMETER DnsServer
Name of the DnsServer to create the record on.
.PARAMETER Ensure
Whether the host record should be present or removed.
#>
function Get-TargetResource
{
[CmdletBinding()]
Expand All @@ -28,7 +49,7 @@ function Get-TargetResource
$Zone,

[Parameter(Mandatory = $true)]
[ValidateSet("ARecord", "CName")]
[ValidateSet("ARecord", "CName", "Ptr")]
[System.String]
$Type,

Expand Down Expand Up @@ -67,6 +88,10 @@ function Get-TargetResource
{
$recordData = $record.RecordData.IPv4address.IPAddressToString
}
if ($Type -eq "PTR")
{
$recordData = ($record.RecordData.PtrDomainName).TrimEnd('.')
}

return @{
Name = $record.HostName;
Expand All @@ -77,6 +102,28 @@ function Get-TargetResource
}
} #end function Get-TargetResource

<#
.SYNOPSIS
This will set the resource to the desired state.
.PARAMETER Name
Specifies the name of the DNS server resource record object.
.PARAMETER Zone
Specifies the name of a DNS zone.
.PARAMETER Type
Specifies the type of DNS record.
.PARAMETER Target
Specifies the Target Hostname or IP Address.
.PARAMETER DnsServer
Name of the DnsServer to create the record on.
.PARAMETER Ensure
Whether the host record should be present or removed.
#>
function Set-TargetResource
{
[CmdletBinding()]
Expand All @@ -91,7 +138,7 @@ function Set-TargetResource
$Zone,

[Parameter(Mandatory = $true)]
[ValidateSet("ARecord", "CName")]
[ValidateSet("ARecord", "CName", "Ptr")]
[System.String]
$Type,

Expand Down Expand Up @@ -123,13 +170,17 @@ function Set-TargetResource
$DNSParameters.Add('CName',$true)
$DNSParameters.Add('HostNameAlias',$Target)
}
if ($Type -eq "PTR")
{
$DNSParameters.Add('Ptr',$true)
$DNSParameters.Add('PtrDomainName',$Target)
}

Write-Verbose -Message ($LocalizedData.CreatingDnsRecordMessage -f $Type, $Target, $Zone, $DnsServer)
Add-DnsServerResourceRecord @DNSParameters
}
elseif ($Ensure -eq 'Absent')
{

$DNSParameters.Add('Force',$true)

if ($Type -eq "ARecord")
Expand All @@ -140,11 +191,37 @@ function Set-TargetResource
{
$DNSParameters.Add('RRType','CName')
}
if ($Type -eq "PTR")
{
$DNSParameters.Add('RRType','Ptr')
}
Write-Verbose -Message ($LocalizedData.RemovingDnsRecordMessage -f $Type, $Target, $Zone, $DnsServer)
Remove-DnsServerResourceRecord @DNSParameters
}
} #end function Set-TargetResource

<#
.SYNOPSIS
This will return whether the resource is in desired state.
.PARAMETER Name
Specifies the name of the DNS server resource record object.
.PARAMETER Zone
Specifies the name of a DNS zone.
.PARAMETER Type
Specifies the type of DNS record.
.PARAMETER Target
Specifies the Target Hostname or IP Address.
.PARAMETER DnsServer
Name of the DnsServer to create the record on.
.PARAMETER Ensure
Whether the host record should be present or removed.
#>
function Test-TargetResource
{
[CmdletBinding()]
Expand All @@ -160,7 +237,7 @@ function Test-TargetResource
$Zone,

[Parameter(Mandatory = $true)]
[ValidateSet("ARecord", "CName")]
[ValidateSet("ARecord", "CName", "Ptr")]
[System.String]
$Type,

Expand Down
10 changes: 5 additions & 5 deletions DSCResources/MSFT_xDnsRecord/MSFT_xDnsRecord.schema.mof
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[ClassVersion("1.0.0.0"), FriendlyName("xDnsRecord")]
class MSFT_xDnsRecord : OMI_BaseResource
{
[Key] string Name;
[Key] string Zone;
[Required, ValueMap{"ARecord","CName"}, Values{"ARecord","CName"}] string Type;
[Key] string Target;
[Write] string DnsServer;
[Key, Description("Specifies the name of the DNS server resource record object.")] string Name;
[Key, Description("Specifies the name of a DNS zone.")] string Zone;
[Required, Description("Specifies the type of DNS record."), ValueMap{"ARecord","CName","Ptr"}, Values{"ARecord","CName","Ptr"}] string Type;
[Key, Description("Specifies the Target Hostname or IP Address.")] string Target;
[Write, Description("Name of the DnsServer to create the record on.")] string DnsServer;
[Write, Description("Should this DNS resource record be present or absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
};

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Get-TargetResource
$dnsServerZone = Get-DnsServerZone -Name $Name -ErrorAction SilentlyContinue;

$targetResource = @{
Name = $dnsServerZone.Name;
Name = $dnsServerZone.ZoneName;
ZoneFile = $dnsServerZone.ZoneFile;
DynamicUpdate = $dnsServerZone.DynamicUpdate;
Ensure = if ($null -eq $dnsServerZone) { 'Absent' } else { 'Present' };
Expand Down
189 changes: 189 additions & 0 deletions DSCResources/MSFT_xDnsServerZoneAging/MSFT_xDnsServerZoneAging.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@

<#
.SYNOPSIS
Get the DNS zone aging settings.
.PARAMETER Name
Name of the DNS forward or reverse loookup zone.
.PARAMETER Enabled
Option to enable scavenge stale resource records on the zone.
#>
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Name,

[Parameter(Mandatory = $true)]
[System.Boolean]
$Enabled
)

Write-Verbose -Message "Getting the DNS zone aging for $Name."

# Get the current zone aging from the local DNS server
$zoneAging = Get-DnsServerZoneAging -Name $Name

return @{
Name = $Name
Enabled = $zoneAging.AgingEnabled
RefreshInterval = $zoneAging.RefreshInterval.TotalHours
NoRefreshInterval = $zoneAging.NoRefreshInterval.TotalHours
}
}

<#
.SYNOPSIS
Set the DNS zone aging settings.
.PARAMETER Name
Name of the DNS forward or reverse loookup zone.
.PARAMETER Enabled
Option to enable scavenge stale resource records on the zone.
.PARAMETER RefreshInterval
Refresh interval for record scavencing in hours. Default value is 7 days.
.PARAMETER NoRefreshInterval
No-refresh interval for record scavencing in hours. Default value is 7 days.
#>
function Set-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Name,

[Parameter(Mandatory = $true)]
[System.Boolean]
$Enabled,

[Parameter()]
[System.UInt32]
$RefreshInterval = 168,

[Parameter()]
[System.UInt32]
$NoRefreshInterval = 168
)

$currentConfiguration = Get-TargetResource -Name $Name -Enabled $Enabled

# Enable or disable zone aging
if ($currentConfiguration.Enabled -ne $Enabled)
{
if ($Enabled)
{
Write-Verbose -Message "Enable DNS zone aging on $Name."
}
else
{
Write-Verbose -Message "Disable DNS zone aging on $Name."
}

Set-DnsServerZoneAging -Name $Name -Aging $Enabled -WarningAction 'SilentlyContinue'
}

# Update the refresh interval
if ($PSBoundParameters.ContainsKey('RefreshInterval'))
{
if ($currentConfiguration.RefreshInterval -ne $RefreshInterval)
{
Write-Verbose -Message "Set DNS zone refresh interval to $RefreshInterval hours."

$refreshIntervalTimespan = [System.TimeSpan]::FromHours($RefreshInterval)

<#
Hide the following warning if aging is not enabled: Specified
parameters related to aging of records have been set. However,
aging was not enabled and hence the settings are ineffective.
#>
Set-DnsServerZoneAging -Name $Name -RefreshInterval $refreshIntervalTimespan -WarningAction 'SilentlyContinue'
}
}

# Update the no refresh interval
if ($PSBoundParameters.ContainsKey('NoRefreshInterval'))
{
if ($currentConfiguration.NoRefreshInterval -ne $NoRefreshInterval)
{
Write-Verbose -Message "Set DNS zone no refresh interval to $NoRefreshInterval hours."

$noRefreshIntervalTimespan = [System.TimeSpan]::FromHours($NoRefreshInterval)

<#
Hide the following warning if aging is not enabled: Specified
parameters related to aging of records have been set. However,
aging was not enabled and hence the settings are ineffective.
#>
Set-DnsServerZoneAging -Name $Name -NoRefreshInterval $noRefreshIntervalTimespan -WarningAction 'SilentlyContinue'
}
}
}

<#
.SYNOPSIS
Test the DNS zone aging settings.
.PARAMETER Name
Name of the DNS forward or reverse loookup zone.
.PARAMETER Enabled
Option to enable scavenge stale resource records on the zone.
.PARAMETER RefreshInterval
Refresh interval for record scavencing in hours. Default value is 7 days.
.PARAMETER NoRefreshInterval
No-refresh interval for record scavencing in hours. Default value is 7 days.
#>
function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Name,

[Parameter(Mandatory = $true)]
[System.Boolean]
$Enabled,

[Parameter()]
[System.UInt32]
$RefreshInterval = 168,

[Parameter()]
[System.UInt32]
$NoRefreshInterval = 168
)

Write-Verbose -Message "Testing the DNS zone aging for $Name."

$currentConfiguration = Get-TargetResource -Name $Name -Enabled $Enabled

$isDesiredState = $currentConfiguration.Enabled -eq $Enabled

if ($PSBoundParameters.ContainsKey('RefreshInterval'))
{
$isDesiredState = $isDesiredState -and $currentConfiguration.RefreshInterval -eq $RefreshInterval
}

if ($PSBoundParameters.ContainsKey('NoRefreshInterval'))
{
$isDesiredState = $isDesiredState -and $currentConfiguration.NoRefreshInterval -eq $NoRefreshInterval
}

return $isDesiredState
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[ClassVersion("1.0.0.0"), FriendlyName("xDnsServerZoneAging")]
class MSFT_xDnsServerZoneAging : OMI_BaseResource
{
[Key, Description("Name of the DNS forward or reverse loookup zone.")] String Name;
[Required, Description("Option to enable scavenge stale resource records on the zone.")] Boolean Enabled;
[Write, Description("Refresh interval for record scavencing in hours. Default value is 7 days.")] UInt32 RefreshInterval;
[Write, Description("No-refresh interval for record scavencing in hours. Default value is 7 days.")] UInt32 NoRefreshInterval;
};
Loading

0 comments on commit e2a372a

Please sign in to comment.