-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-DnsServerSearchOrder.ps1
88 lines (78 loc) · 4 KB
/
Get-DnsServerSearchOrder.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function Get-DnsServerSearchOrder
{
<#
.SYNOPSIS
Veiw and report on DNS client configuration.
.DESCRIPTION
Find the primary and secondary DNS servers on one or more computers.
.PARAMETER ComputerName
Array of computers to be queried.
.EXAMPLE
PS C:\> Get-DnsServerSearchOrder -ComputerName Server1
.EXAMPLE
PS C:\> "Server1",Server2" | Get-DnsServerSearchOrder
.NOTES
Name: Get-DnsServerSearchOrder.ps1
Author: Jason Roth
DateCreated: 3.27.2014
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$false,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[alias('Name')]
[array]$ComputerName = 'localhost'
)
begin
{
$Output = @()
}
process
{
foreach ($Computer in $ComputerName)
{
if (Test-Connection -ComputerName $Computer -Count 1 -Quiet)
{
$Nics = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer | Where {$_.IPEnabled}
if ($Nics)
{
foreach ($Nic in $Nics)
{
$Settings = $Nic.DNSServerSearchOrder
$Properties = [ordered] @{
Server = $Computer
NetworkCard = $Nic.Caption
Address = $Nic.IPAddress[0]
PrimaryDns = $Settings[0]
SecondaryDns = $Settings[1]
TertiaryDns = $Settings[2]
QuaternaryDns = $Settings[3]}
$Object = New-Object -TypeName PSObject -Property $Properties
$Output +=$Object}
}
else
{
$Properties = [ordered] @{
Server = $Computer
Error = "Unable to connect via WMI"}
$Object = New-Object -TypeName PSObject -Property $Properties
$Output +=$Object
}
}
else
{
$Properties = [ordered] @{
Server = $Computer
Error = "Unable to ping"}
$Object = New-Object -TypeName PSObject -Property $Properties
$Output +=$Object
}
}
}
end
{
Write-Output $Output
}
}