-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathChecking IPPool for resolved names and naming convention
102 lines (92 loc) · 3.46 KB
/
Checking IPPool for resolved names and naming convention
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
98
99
100
101
# Get the Pools
$Pools = Get-SCStaticIPAddressPool -VMMServer $VMMServer | Where {$_.Name -in @('VMPool', 'ListenerPool', 'ClusterPool') -and $_.LogicalNetworkDefinition -like '*LS*'}
$Answer = foreach ($pool in $Pools) {
$Name = $pool.Name
Write-PSFMessage "Working on Pool - $Name " -Verbose
# split them up to get the base and the4 last octet
$StartIp = [IPAddress]$pool.IPAddressRangeStart
$StartIpLastOctet = $StartIp.GetAddressBytes()[-1]
$NetworkBase = $StartIp.GetAddressBytes()[0..2] -join "."
$EndIP = [IPAddress]$pool.IPAddressRangeEnd
$EndIPLastOctet = $EndIP.GetAddressBytes()[-1]
$DNSRecords = Get-WmiObject -Class MicrosoftDNS_AType -NameSpace Root\MicrosoftDNS -ComputerName 10.202.31.30 -Filter "DomainName = 'ls1test.local'" | Select-Object -property Ownername, ipaddress
$IP = $StartIpLastOctet
#loop through them
While ($IP -le $EndIPLastOctet) {
$IPAddress = $NetworkBase + "." + $IP
Write-PSFMessage "Working on IPADdress $IPAddress" -Verbose
try {
$resolves = Resolve-DnsName $IPAddress -ErrorAction Stop
$Resolved = $true
$VMName = $resolves.NameHost
switch ($Name) {
VMPool {
if ($VMName -like '*VM*') {
$ISDba = $true
}
else {
$ISDba = $False
}
}
ListenerPool {
if ($VMName -like '*DB*') {
$ISDba = $true
}
else {
$ISDba = $False
}
}
ClusterPool {
$ISDba = $False
}
Default {}
}
}
catch {
<#
if ($Name -eq 'ClusterPool') {
Write-PSFMessage "Trying IPADdress $IPAddress as Cluster" -Verbose
try {
$resolves = Resolve-DnsName (Get-Cluster $IPAddress -ErrorAction Stop).Name -ErrorAction Stop
$Resolved = $true
$VMName = $resolves.Name
if ($VMName -like '*CLU*') {
$ISDba = $true
}
else {
$ISDba = $False
}
}
Catch {
$Resolved = $false
$VMName = 'Nobody Knows'
}
}#>
if($Name -eq 'ListenerPool' -or $Name -eq 'ClusterPool'){
Write-PSFMessage "Trying IPADdress $IPAddress" -Verbose
if($IPaddress -in $DNSRecords.IPADdress){
$VMName = $DNSRecords.Where{$_.IpAddress -eq $IPAddress}.OwnerName -Join " "
if ($VMName -like '*DB*' -or $VMName -like '*CLU*') {
$ISDba = $true
}
else {
$ISDba = $False
}
}
}
else {
$Resolved = $false
$VMName = 'Nobody Knows'
}
}
[PSCustomObject]@{
PoolName = $Name
IPAddress = $IPAddress
Resolved = $Resolved
IsDBA = $ISDba
VMName = $VMName
}
Write-PSFMessage "Finished IPADdress $IPAddress" -Verbose
$IP ++
}
}