forked from PoeBlu/powershell-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-DNSandWins.ps1
More file actions
96 lines (81 loc) · 5.88 KB
/
Get-DNSandWins.ps1
File metadata and controls
96 lines (81 loc) · 5.88 KB
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
89
90
91
92
93
94
95
96
# Get-DNSandWINS.ps1
# Written by Bill Stewart (bstewart@iname.com)
#requires -version 2
# Version history:
#
# 2.0 (2013-10-02)
# * Added -Credential
# * Output data only for IPv4 addresses
# * Output separate row for each DNS server address
#
# 1.0 (2012-02-15)
# * Initial version
<#
.SYNOPSIS
Outputs the computer name, IP address(es), DNS server address(es), and WINS server addresses for one or more computers.
.DESCRIPTION
Outputs the computer name, IP address(es), DNS server address(es), and WINS server addresses for one or more computers.
.PARAMETER ComputerName
One or more computer names. This parameter accepts pipeline input.
.PARAMETER Credential
Specifies credentials for the WMI connection.
.EXAMPLE
PS C:\> Get-DNSandWINS server1
Outputs information for server1.
.EXAMPLE
PS C:\> Get-DNSandWINS server1,server2
Outputs information for server1 and server2.
.EXAMPLE
PS C:\> Get-DNSandWINS (Get-Content ComputerList.txt)
Outputs information for the computers listed in ComputerList.txt.
.EXAMPLE
PS C:\> Get-Content ComputerList.txt | Get-DNSandWINS
Same as previous example (Outputs information for the computers listed in ComputerList.txt).
.EXAMPLE
PS C:\> Get-DNSandWINS server1,server2 -Credential (Get-Credential)
Outputs information for server1 and server2 using different credentials.
#>
param(
[parameter(ValueFromPipeline=$TRUE)]
[String[]] $ComputerName=$Env:COMPUTERNAME,
[System.Management.Automation.PSCredential] $Credential
)
begin {
$PipelineInput = (-not $PSBOUNDPARAMETERS.ContainsKey("ComputerName")) -and (-not $ComputerName)
# Outputs the computer name, IP address, and DNS and WINS settings for
# every IP-enabled adapter on the specified computer that's configured with
# an IPv4 address.
function Get-IPInfo($computerName) {
$params = @{
"Class" = "Win32_NetworkAdapterConfiguration"
"ComputerName" = $computerName
"Filter" = "IPEnabled=True"
}
if ( $Credential ) { $params.Add("Credential", $Credential) }
get-wmiobject @params | foreach-object {
foreach ( $adapterAddress in $_.IPAddress ) {
if ( $adapterAddress -match '(\d{1,3}\.){3}\d{1,3}' ) {
foreach ( $dnsServerAddress in $_.DNSServerSearchOrder ) {
new-object PSObject -property @{
"ComputerName" = $_.__SERVER
"IPAddress" = $adapterAddress
"DNSServer" = $dnsServerAddress
"WINSPrimaryServer" = $_.WINSPrimaryServer
"WINSSecondaryServer" = $_.WINSSecondaryServer
} | select-object ComputerName,IPAddress,DNSServer,WINSPrimaryServer,WINSSecondaryServer
}
}
}
}
}
}
process {
if ( $PipelineInput ) {
Get-IPInfo $_
}
else {
$ComputerName | foreach-object {
Get-IPInfo $_
}
}
}