-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheck-HANetwork.ps1
151 lines (143 loc) · 5.43 KB
/
Check-HANetwork.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<#
.SYNOPSIS
Checks if HA network is available for specified cluster.
.DESCRIPTION
This script takes a clustername and switch name input to check HA availability.
.PARAMETER clusterName
name of HA cluster to test
.PARAMETER switchName
name of switch to test against
.EXAMPLE
.\Check-HANetwork.ps1 cluster01 switch01
This would test the cluster 'cluster01' against the switch 'switch01'
#>
function CompareList($list1, $list2)
{
if( $list1.count -ne $list2.count )
{
return $false
}
for($i = 0; $i -lt $list1.count; $i++)
{
if( $list1[$i].ToString() -ne $list2[$i].ToString() )
{
return $false
}
}
return $true
}
function ValidateHANetwork($clusterName, $switchName)
{
$validationResult = $true
$cluster = Get-SCVMHostCluster -name $clusterName
$vNic = Get-SCVirtualNetwork -VMHost $cluster.nodes[0] | where {$_.name -eq $switchName}
if( $vNic -eq $null )
{
Write-Host "Virtual Switch not found in host " $cluster.nodes[0].Name
$validationResult = $false
}
else
{
if( $vNic.VMHostNetworkAdapters.Count -eq 0 )
{
Write-Host "Virtual Switch not attached to external network card on host " + $cluster.nodes[0].Name
$validationResult = $false
}
else
{
foreach($node in $cluster.nodes)
{
Write-Host "==========================================================================="
Write-Host "Comparing " $node.Name
Write-Host "==========================================================================="
$vNicToCompare = Get-SCVirtualNetwork -VMHost $node | where {$_.name -eq $switchName}
if( $vNicToCompare -eq $null )
{
$validationResult = $false
Write-Host "Virtual Switch not found in host " $node.Name
}
if( $vNicToCompare.VMHostNetworkAdapters.Count -eq 0)
{
$validationResult = $false
Write-Host "Virtual Switch not attached to external network card on host " $node.Name
}
if( $vNic.VMHostNetworkAdapters[0].LogicalNetworks -eq $null )
{
if( $vNicToCompare.VMHostNetworkAdapters[0].LogicalNetworks -ne $null )
{
$validationResult = $false
Write-Host "Net Adapter " $vNic.VMHostNetworkAdapters.Name " for " $cluster.nodes[0].name " is not connected to logical network but Net adapter " $vNicToCompare.VMHostNetworkAdapters.Name " for " $node.Name
}
}
else
{
$ln1 = @($vNic.VMHostNetworkAdapters[0].LogicalNetworks | Sort-Object Name)
$ln2 = @($vNicToCompare.VMHostNetworkAdapters[0].LogicalNetworks | Sort-Object Name)
$ln1Id = @($vNic.VMHostNetworkAdapters[0].LogicalNetworks | Sort-Object ID | select ID)
$ln2Id = @($vNicToCompare.VMHostNetworkAdapters[0].LogicalNetworks | Sort-Object ID | select ID)
$result = CompareList $ln1Id $ln2Id
if( $result -eq $false )
{
Write-Host "Logical Networks on Adapters don't match"
Write-Host "------------------------------------------------"
Write-Host "Host " $cluster.nodes[0].name " Logical networks for adapter " $vNic.VMHostNetworkAdapters[0].Name
@($ln1) | ft *
Write-Host "------------------------------------------------"
Write-Host "Host " $node.name " Logical networks for adapter " $vNicToCompare.VMHostNetworkAdapters[0].Name
@($ln2) | ft *
Write-Host "------------------------------------------------"
$validationResult = $false
}
else
{
$sub1 = @($vNic.VMHostNetworkAdapters[0].SubnetVLans | Sort-Object Name)
$sub2 = @($vNicToCompare.VMHostNetworkAdapters[0].SubnetVLans | Sort-Object Name)
$sub1Id = @($vNic.VMHostNetworkAdapters[0].SubnetVLans | Sort-Object ID | select ID)
$sub2Id = @($vNicToCompare.VMHostNetworkAdapters[0].SubnetVLans | Sort-Object ID | select ID)
$result = CompareList $sub1Id $sub2Id
if( $result -eq $false )
{
Write-Host "Subnets on Adapters don't match"
Write-Host "------------------------------------------------"
Write-Host "Host " $cluster.nodes[0].name " Subnets"
@($sub1) | ft *
Write-Host "------------------------------------------------"
Write-Host "Host " $node.name " Subnets"
@($sub2) | ft *
Write-Host "------------------------------------------------"
$validationResult = $false
}
else
{
if($vNic.VMHostNetworkAdapters[0].VLanMode -ne $vNicToCompare.VMHostNetworkAdapters[0].VLanMode)
{
Write-Host "VlanModes on Adapters don't match"
Write-Host "------------------------------------------------"
Write-Host "Host " $cluster.nodes[0].name " Subnets"
$vNic.VMHostNetworkAdapters[0].VLanMode
Write-Host "------------------------------------------------"
Write-Host "Host " $node.name " Subnets"
$vNicToCompare.VMHostNetworkAdapters[0].VLanMode
Write-Host "------------------------------------------------"
$validationResult = $false
}
}
}
}
}
}
}
return $validationResult
}
if ($args.Length -ne 2 )
{
Write-Host "Usage: Check-HANetwork <clusterName> <switchName>"
}
else
{
$result = ValidateHANetwork $args[0] $args[1]
if( $result -eq $true)
{
Write-Host "The cluster virutal network is HA and is configured correctly"
}
}