forked from bcdady/MyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest-DnsZone.ps1
74 lines (67 loc) · 2.34 KB
/
Test-DnsZone.ps1
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
#requires -Module PoshRSJob
<#PSScriptInfo
.VERSION
0.0.1
.GUID
8bbc7734-6854-4441-8022-dc394fa335ff
.AUTHOR
Joshua (Windos) King
.COMPANYNAME
king.geek.nz
.COPYRIGHT
(c) 2016 Joshua (Windos) King. All rights reserved.
.TAGS
DNS
.PROJECTURI
https://github.com/Windos/powershell-depot/tree/master/GalleryScripts
.RELEASENOTES
* Initial release
#>
<#
.SYNOPSIS
Tests for potentially stale DNS records in a DNS Zone.
.DESCRIPTION
Script to test for potentially stale DNS records in a DNS Zone.
Leverages PoshRSJob to test multiple records in parallel.
.EXAMPLE
Test-DnsZone -Zone campus.example.com
Tests all Host and Alias records in the 'Campus' DNS zone, and returns any that do not respond the an echo request.
.EXAMPLE
Test-DnsZone -Zone campus.example.com -all
Tests all Host and Alias records in the 'Campus' DNS zone, and returns all records regardless of echo response.
#>
[CmdletBinding(DefaultParameterSetName='Filtered')]
[OutputType('System.Management.Automation.PSCustomObject')]
Param
(
[Parameter(Position = 0,
Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $ZoneName,
# Specifies that all records should be returned regardless of echo response
[switch] $All,
[ValidateNotNullOrEmpty()]
[string] $ComputerName = ((Get-ADDomainController -Discover -Service PrimaryDC).HostName)
)
$ScriptBlock = {
[PSCustomObject] @{
Name = $_.HostName
Address = $_.RecordData.IPv4Address.ToString()
Echo = Test-Connection -Count 1 -ComputerName $_.HostName -Quiet
}
}
Import-Module -Name PoshRSJob
try {
Import-Module -Name DnsServer
}
catch {
throw 'Unable to load module ''DnsServer''. Please ensure you have installed and enabled the Remote Server Administation Tools (RSAT).'
}
$Records = Get-DnsServerResourceRecord -ComputerName $ComputerName -ZoneName $ZoneName | Where { $_.Type -in 1,5 }
$Batch = "DnsTest-$(New-Guid)"
if ($all) {
$Records | Start-RSJob $ScriptBlock -Name {$_.HostName} -Throttle 20 -Batch $Batch | Wait-RSJob -ShowProgress | Receive-RSJob
} else {
$Records | Start-RSJob $ScriptBlock -Name {$_.HostName} -Throttle 20 -Batch $Batch | Wait-RSJob -ShowProgress | Receive-RSJob | Where Echo -eq $false
}
Get-RSJob -Batch $Batch | Remove-RSJob