Skip to content

Commit

Permalink
Merge pull request #71 from PowerShell/dev
Browse files Browse the repository at this point in the history
Release of version 1.10.0.0 of xDnsServer
  • Loading branch information
kwirkykat authored May 2, 2018
2 parents 6a7ac5d + df75d31 commit 3ea67af
Show file tree
Hide file tree
Showing 18 changed files with 383 additions and 171 deletions.
6 changes: 6 additions & 0 deletions .MetaTestOptIn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"Common Tests - Validate Markdown Files",
"Common Tests - Validate Module Files",
"Common Tests - Validate Script Files",
"Common Tests - Validate Example Files"
]
25 changes: 13 additions & 12 deletions DSCResources/Helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ function New-TerminatingError
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[String]
$errorId,

[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[String]
$errorMessage,

[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[System.Management.Automation.ErrorCategory]
$errorCategory
)
Expand All @@ -37,7 +37,7 @@ function Assert-Module
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[string]
$Name
)
Expand All @@ -56,7 +56,7 @@ function Remove-CommonParameter
[cmdletbinding()]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[hashtable]
$Hashtable
)
Expand All @@ -77,17 +77,19 @@ function Test-DscParameterState
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[hashtable]
$CurrentValues,

[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[object]
$DesiredValues,

[Parameter()]
[string[]]
$ValuesToCheck,

[Parameter()]
[switch]$TurnOffTypeChecking
)

Expand Down Expand Up @@ -137,9 +139,8 @@ function Test-DscParameterState
}

if (-not $TurnOffTypeChecking)
{
if (($desiredType.Name -ne 'Unknown' -and $currentType.Name -ne 'Unknown') -and
$desiredType.FullName -ne $currentType.FullName)
{
if (($desiredType.Name -ne 'Unknown' -and $currentType.Name -ne 'Unknown') -and $desiredType.FullName -ne $currentType.FullName)
{
Write-Verbose -Message "NOTMATCH: Type mismatch for property '$key' Current state type is '$($currentType.Name)' and desired type is '$($desiredType.Name)'"
continue
Expand Down Expand Up @@ -253,10 +254,10 @@ function Test-DSCObjectHasProperty
[OutputType([bool])]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[object]$Object,

[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[string]$PropertyName
)

Expand Down
18 changes: 13 additions & 5 deletions DSCResources/MSFT_xDnsARecord/MSFT_xDnsARecord.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-TargetResource
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
Expand All @@ -24,7 +24,8 @@
Write-Warning -Message "DSC Resource xDnsARecord has been replaced by xDNSRecord, and will be removed in a future version"
Write-Verbose "Looking up DNS record for $Name in $Zone"
$record = Get-DnsServerResourceRecord -ZoneName $Zone -Name $Name -ErrorAction SilentlyContinue
if ($null -eq $record) {
if ($null -eq $record)
{
return @{
Name = $Name;
Zone = $Zone;
Expand Down Expand Up @@ -65,7 +66,8 @@ function Set-TargetResource
[System.String]
$Ensure = 'Present'
)
if ($Ensure -eq 'Present') {
if ($Ensure -eq 'Present')
{
Write-Verbose "Creating for DNS $Target in $Zone"
Add-DnsServerResourceRecordA -IPv4Address $Target -Name $Name -ZoneName $Zone
}
Expand Down Expand Up @@ -102,8 +104,14 @@ function Test-TargetResource

Write-Verbose "Testing for DNS $Name in $Zone"
$result = @(Get-TargetResource @PSBoundParameters)
if ($Ensure -ne $result.Ensure) { return $false }
elseif ($Ensure -eq 'Present' -and ($result.Target -ne $Target)) { return $false }
if ($Ensure -ne $result.Ensure)
{
return $false
}
elseif ($Ensure -eq 'Present' -and ($result.Target -ne $Target))
{
return $false
}
return $true
}

Expand Down
113 changes: 74 additions & 39 deletions DSCResources/MSFT_xDnsServerADZone/MSFT_xDnsServerADZone.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ data LocalizedData
{
# culture="en-US"
ConvertFrom-StringData @'
CheckingZoneMessage = Checking DNS server zone with name '{0}' is '{1}'...
AddingZoneMessage = Adding DNS server zone '{0}' ...
RemovingZoneMessage = Removing DNS server zone '{0}' ...
CheckingZoneMessage = Checking DNS server zone with name '{0}' is '{1}'...
AddingZoneMessage = Adding DNS server zone '{0}' ...
RemovingZoneMessage = Removing DNS server zone '{0}' ...
CheckPropertyMessage = Checking DNS server zone property '{0}' ...
NotDesiredPropertyMessage = DNS server zone property '{0}' is not correct. Expected '{1}', actual '{2}'
SetPropertyMessage = DNS server zone property '{0}' is set
CheckPropertyMessage = Checking DNS server zone property '{0}' ...
NotDesiredPropertyMessage = DNS server zone property '{0}' is not correct. Expected '{1}', actual '{2}'
SetPropertyMessage = DNS server zone property '{0}' is set
CredentialRequiresComputerNameMessage = The Credentials Parameter can only be used when ComputerName is also specified.
'@
}

Expand All @@ -21,7 +23,7 @@ function Get-TargetResource
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Name,
Expand All @@ -31,7 +33,7 @@ function Get-TargetResource
[System.String]
$DynamicUpdate = 'Secure',

[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateSet('Custom','Domain','Forest','Legacy')]
[System.String]
$ReplicationScope,
Expand All @@ -55,26 +57,39 @@ function Get-TargetResource
)
Assert-Module -Name 'DNSServer'
Write-Verbose ($LocalizedData.CheckingZoneMessage -f $Name, $Ensure)
$cimSessionParams = @{ErrorAction = 'SilentlyContinue'}
if ($ComputerName)
{
$cimSessionParams += @{ComputerName = $ComputerName}
}
else
{
$cimSessionParams += @{ComputerName = $env:COMPUTERNAME}
}
if ($Credential)

if (!$PSBoundParameters.ContainsKey('ComputerName') -and $PSBoundParameters.ContainsKey('Credential'))
{
$cimSessionParams += @{Credential = $Credential}
throw $LocalizedData.CredentialRequiresComputerNameMessage
}
$cimSession = New-CimSession @cimSessionParams

$getParams = @{
Name = $Name
CimSession = $cimSession
ErrorAction = 'SilentlyContinue'
}

if ($PSBoundParameters.ContainsKey('ComputerName'))
{
$cimSessionParams = @{
ErrorAction = 'SilentlyContinue'
ComputerName = $ComputerName
}
if ($PSBoundParameters.ContainsKey('Credential'))
{
$cimSessionParams += @{
Credential = $Credential
}
}
$getParams = @{
CimSession = New-CimSession @cimSessionParams
}
}

$dnsServerZone = Get-DnsServerZone @getParams
if ($getParams.CimSession)
{
Remove-CimSession -CimSession $getParams.CimSession
}
$targetResource = @{
Name = $dnsServerZone.ZoneName
DynamicUpdate = $dnsServerZone.DynamicUpdate
Expand All @@ -91,7 +106,7 @@ function Test-TargetResource
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Name,
Expand All @@ -101,7 +116,7 @@ function Test-TargetResource
[System.String]
$DynamicUpdate = 'Secure',

[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateSet('Custom','Domain','Forest','Legacy')]
[System.String]
$ReplicationScope,
Expand Down Expand Up @@ -169,7 +184,7 @@ function Set-TargetResource
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Name,
Expand All @@ -179,7 +194,7 @@ function Set-TargetResource
[System.String]
$DynamicUpdate = 'Secure',

[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateSet('Custom','Domain','Forest','Legacy')]
[System.String]
$ReplicationScope,
Expand All @@ -203,55 +218,75 @@ function Set-TargetResource
)
Assert-Module -Name 'DNSServer'
$targetResource = Get-TargetResource @PSBoundParameters

$params = @{
Name = $Name
}

if ($PSBoundParameters.ContainsKey('ComputerName'))
{
$cimSessionParams = @{
ErrorAction = 'SilentlyContinue'
ComputerName = $ComputerName
}
if ($PSBoundParameters.ContainsKey('Credential'))
{
$cimSessionParams += @{
Credential = $Credential
}
}
$params += @{
CimSession = New-CimSession @cimSessionParams
}
}

if ($Ensure -eq 'Present')
{
if ($targetResource.Ensure -eq 'Present')
{
## Update the existing zone
$updateParams = @{
Name = $targetResource.Name
CimSession = $targetResource.CimSession
}
if ($targetResource.DynamicUpdate -ne $DynamicUpdate)
{
$updateParams += @{DynamicUpdate = $DynamicUpdate}
$params += @{DynamicUpdate = $DynamicUpdate}
Write-Verbose ($LocalizedData.SetPropertyMessage -f 'DynamicUpdate')
}
if ($targetResource.ReplicationScope -ne $ReplicationScope)
{
$updateParams += @{ReplicationScope = $ReplicationScope}
$params += @{ReplicationScope = $ReplicationScope}
Write-Verbose ($LocalizedData.SetPropertyMessage -f 'ReplicationScope')
}
if ($DirectoryPartitionName -and $targetResource.DirectoryPartitionName -ne $DirectoryPartitionName)
{
$updateParams += @{DirectoryPartitionName = $DirectoryPartitionName}
$params += @{DirectoryPartitionName = $DirectoryPartitionName}
Write-Verbose ($LocalizedData.SetPropertyMessage -f 'DirectoryPartitionName')
}
Set-DnsServerPrimaryZone @updateParams
Set-DnsServerPrimaryZone @params
}
elseif ($targetResource.Ensure -eq 'Absent')
{
## Create the zone
Write-Verbose ($LocalizedData.AddingZoneMessage -f $targetResource.Name)
$addParams = @{
Name = $Name
$params += @{
DynamicUpdate = $DynamicUpdate
ReplicationScope = $ReplicationScope
CimSession = $targetResource.CimSession
}
if ($DirectoryPartitionName)
{
$addParams += @{
$params += @{
DirectoryPartitionName = $DirectoryPartitionName
}
}
Add-DnsServerPrimaryZone @addParams
Add-DnsServerPrimaryZone @params
}
}
elseif ($Ensure -eq 'Absent')
{
# Remove the DNS Server zone
Write-Verbose ($LocalizedData.RemovingZoneMessage -f $targetResource.Name)
Remove-DnsServerZone -Name $targetResource.Name -ComputerName $ComputerName -Force
Remove-DnsServerZone @params -Force
}
if ($params.CimSession)
{
Remove-CimSession -CimSession $params.CimSession
}
} #end function Set-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function Get-TargetResource
[OutputType([Hashtable])]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[string]
$IsSingleInstance,
Expand All @@ -29,7 +29,7 @@ function Set-TargetResource
{
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[string]
$IsSingleInstance,
Expand All @@ -56,7 +56,7 @@ function Test-TargetResource
[OutputType([Bool])]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[string]
$IsSingleInstance,
Expand Down
Loading

0 comments on commit 3ea67af

Please sign in to comment.