-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGet-DNSHostEntryAsync.ps1
More file actions
97 lines (88 loc) · 3.14 KB
/
Get-DNSHostEntryAsync.ps1
File metadata and controls
97 lines (88 loc) · 3.14 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
97
Function Get-DNSHostEntryAsync {
<#
.SYNOPSIS
Performs a DNS Get Host asynchronously
.DESCRIPTION
Performs a DNS Get Host asynchronously
.PARAMETER Computername
List of computers to check Get Host against
.NOTES
Name: Get-DNSHostEntryAsync
Author: Boe Prox
Version History:
1.0 //Boe Prox - 12/24/2015
- Initial result
.OUTPUT
Net.AsyncGetHostResult
.EXAMPLE
Get-DNSHostEntryAsync -Computername google.com,prox-hyperv,bing.com, github.com, powershellgallery.com, powershell.org
Computername Result
------------ ------
google.com 216.58.218.142
prox-hyperv 192.168.1.116
bing.com 204.79.197.200
github.com 192.30.252.121
powershellgallery.com 191.234.42.116
powershell.org {104.28.15.25, 104.28.14.25}
.EXAMPLE
Get-DNSHostEntryAsync -Computername 216.58.218.142
Computername Result
------------ ------
216.58.218.142 dfw25s08-in-f142.1e100.net
#>
#Requires -Version 3.0
[OutputType('Net.AsyncGetHostResult')]
[cmdletbinding()]
Param (
[parameter(ValueFromPipeline=$True)]
[string[]]$Computername
)
Begin {
$Computerlist = New-Object System.Collections.ArrayList
If ($PSBoundParameters.ContainsKey('Computername')) {
[void]$Computerlist.AddRange($Computername)
} Else {
$IsPipeline = $True
}
}
Process {
If ($IsPipeline) {
[void]$Computerlist.Add($Computername)
}
}
End {
$Task = ForEach ($Computer in $Computername) {
If (([bool]($Computer -as [ipaddress]))) {
[pscustomobject] @{
Computername = $Computer
Task = [system.net.dns]::GetHostEntryAsync($Computer)
}
} Else {
[pscustomobject] @{
Computername = $Computer
Task = [system.net.dns]::GetHostAddressesAsync($Computer)
}
}
}
Try {
[void][Threading.Tasks.Task]::WaitAll($Task.Task)
} Catch {}
$Task | ForEach {
$Result = If ($_.Task.IsFaulted) {
$_.Task.Exception.InnerException.Message
} Else {
If ($_.Task.Result.IPAddressToString) {
$_.Task.Result.IPAddressToString
} Else {
$_.Task.Result.HostName
}
}
$Object = [pscustomobject]@{
Computername = $_.Computername
Result = $Result
}
$Object.pstypenames.insert(0,'Net.AsyncGetHostResult')
$Object
}
}
}