Skip to content

Commit 701e7ec

Browse files
authored
Merge pull request #2473 from microsoft/dpaul-HcDev
Add NIC Teaming detection
2 parents d7d7508 + 100a96f commit 701e7ec

File tree

6 files changed

+117
-13
lines changed

6 files changed

+117
-13
lines changed

Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerNicSettings.ps1

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,28 @@ function Invoke-AnalyzerNicSettings {
2525
}
2626
$osInformation = $HealthServerObject.OSInformation
2727
$hardwareInformation = $HealthServerObject.HardwareInformation
28+
$nameToInterfaceDescriptionKey = @{}
2829

29-
foreach ($adapter in $osInformation.NetworkInformation.NetworkAdapters) {
30+
foreach ($netAdapter in $osInformation.NetworkInformation.NetworkAdapters.GetNetAdapter) {
31+
$nameToInterfaceDescriptionKey.Add($netAdapter.Name, $netAdapter.InterfaceDescription)
32+
}
33+
34+
foreach ($adapter in $osInformation.NetworkInformation.NetworkAdapters.Adapters) {
3035

3136
if ($adapter.Description -eq "Remote NDIS Compatible Device") {
3237
Write-Verbose "Remote NDIS Compatible Device found. Ignoring NIC."
3338
continue
3439
}
3540

41+
$adapterName = $adapter.Name
42+
43+
if ($adapter.IsTeamedNic -and $null -ne $adapter.TeamedMembers) {
44+
$adapterName = $adapterName + " - ('$([string]::Join("', '", ([array]$adapter.TeamedMembers)))')"
45+
}
46+
3647
$params = $baseParams + @{
3748
Name = "Interface Description"
38-
Details = "$($adapter.Description) [$($adapter.Name)]"
49+
Details = "$($adapter.Description) [$adapterName]"
3950
DisplayCustomTabNumber = 1
4051
}
4152
Add-AnalyzedResultInformation @params
@@ -223,8 +234,15 @@ function Invoke-AnalyzerNicSettings {
223234
Add-AnalyzedResultInformation @params
224235
}
225236

237+
$params = $baseParams + @{
238+
Name = "NIC Teamed"
239+
Details = $adapter.IsTeamedNic
240+
}
241+
Add-AnalyzedResultInformation @params
242+
226243
$adapterDescription = $adapter.Description
227244
$cookedValue = 0
245+
$cookedTeamValue = @{}
228246
$foundCounter = $false
229247

230248
if ($null -eq $osInformation.NetworkInformation.PacketsReceivedDiscarded) {
@@ -244,6 +262,21 @@ function Invoke-AnalyzerNicSettings {
244262
$cookedValue = $prdInstance.CookedValue
245263
$foundCounter = $true
246264
break
265+
} elseif ($adapter.IsTeamedNic) {
266+
foreach ($memberNameKey in $adapter.TeamedMembers) {
267+
if (-not ($nameToInterfaceDescriptionKey.ContainsKey($memberNameKey))) {
268+
Write-Verbose "Failed to find $memberNameKey for counter lookup."
269+
} else {
270+
if ($instanceName -eq $nameToInterfaceDescriptionKey[$memberNameKey] -or
271+
$instanceName -eq $nameToInterfaceDescriptionKey[$memberNameKey].Replace("#", "_")) {
272+
$cookedTeamValue.Add($instanceName, $prdInstance.CookedValue)
273+
}
274+
}
275+
}
276+
277+
if ($cookedTeamValue.Count -eq 0) {
278+
Write-Verbose "Failed to find a counter for adapter for this teamed NIC. $instanceName didn't match."
279+
}
247280
}
248281
}
249282

@@ -260,13 +293,25 @@ function Invoke-AnalyzerNicSettings {
260293
$displayValue = $baseDisplayValue -f $cookedValue, "Warning"
261294
} else {
262295
$displayWriteType = "Red"
263-
$displayValue = [string]::Concat(($baseDisplayValue -f $cookedValue, "Error"), "We are also seeing this value being rather high so this can cause a performance impacted on a system.")
296+
$displayValue = [string]::Concat(($baseDisplayValue -f $cookedValue, "Error"), " We are also seeing this value being rather high so this can cause a performance impact on a system.")
264297
}
265298

266299
if ($adapterDescription -like "*vmxnet3*" -and
267300
$cookedValue -gt 0) {
268301
$knownIssue = $true
269302
}
303+
} elseif ($cookedTeamValue.Count -gt 0) {
304+
$totalCookedValue = 0
305+
$cookedTeamValue.Values | ForEach-Object { $totalCookedValue += [int]$_ }
306+
307+
if ($totalCookedValue -eq 0) {
308+
$displayWriteType = "Green"
309+
} elseif ($totalCookedValue -lt 1000) {
310+
$displayValue = $baseDisplayValue -f "$($totalCookedValue) for all adapters on the team.", "Warning"
311+
} else {
312+
$displayWriteType = "Red"
313+
$displayValue = [string]::Concat(($baseDisplayValue -f "$($totalCookedValue) for all adapters on the team.", "Error"), " We are also seeing this value being rather high so this can cause a performance impact on a system.")
314+
}
270315
} else {
271316
$displayValue = "Couldn't find value for the counter."
272317
$cookedValue = $null
@@ -292,7 +337,7 @@ function Invoke-AnalyzerNicSettings {
292337
}
293338
}
294339

295-
if ($osInformation.NetworkInformation.NetworkAdapters.Count -gt 1) {
340+
if ($osInformation.NetworkInformation.NetworkAdapters.Adapters.Count -gt 1) {
296341
$params = $baseParams + @{
297342
Details = "Multiple active network adapters detected. Exchange 2013 or greater may not need separate adapters for MAPI and replication traffic. For details please refer to https://aka.ms/HC-PlanHA#network-requirements"
298343
AddHtmlDetailRow = $false
@@ -324,7 +369,7 @@ function Invoke-AnalyzerNicSettings {
324369
Add-AnalyzedResultInformation @params
325370
}
326371

327-
$noDNSRegistered = ($osInformation.NetworkInformation.NetworkAdapters | Where-Object { $_.RegisteredInDns -eq $true }).Count -eq 0
372+
$noDNSRegistered = ($osInformation.NetworkInformation.NetworkAdapters.Adapters | Where-Object { $_.RegisteredInDns -eq $true }).Count -eq 0
328373

329374
if ($noDNSRegistered) {
330375
$params = $baseParams + @{

Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-NetworkingInformation.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ function Get-NetworkingInformation {
2121
Get-HttpProxySetting | Invoke-RemotePipelineHandler -Result ([ref]$httpProxy)
2222
Get-LocalizedCounterSamples -MachineName $Server -Counter "\Network Interface(*)\Packets Received Discarded" |
2323
Invoke-RemotePipelineHandler -Result ([ref]$packetsReceivedDiscarded)
24-
Get-AllNicInformation -CatchActionFunction ${Function:Invoke-CatchActions} | Invoke-RemotePipelineHandlerList -Result ([ref]$networkAdapters)
24+
Get-AllNicInformation -CatchActionFunction ${Function:Invoke-CatchActions} | Invoke-RemotePipelineHandler -Result ([ref]$networkAdapters)
2525

26-
foreach ($adapter in $networkAdapters) {
26+
foreach ($adapter in $networkAdapters.Adapters) {
2727
if (-not ($adapter.IPv6Enabled)) {
2828
$ipv6DisabledOnNICs = $true
2929
break
@@ -33,7 +33,7 @@ function Get-NetworkingInformation {
3333
return [PSCustomObject]@{
3434
HttpProxy = $httpProxy
3535
PacketsReceivedDiscarded = $packetsReceivedDiscarded
36-
NetworkAdapters = [array]$networkAdapters
36+
NetworkAdapters = $networkAdapters
3737
IPv6DisabledOnNICs = $ipv6DisabledOnNICs
3838
}
3939
}

Diagnostics/HealthChecker/Tests/HealthChecker.E16.Main.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Describe "Testing Health Checker by Mock Data Imports - Exchange 2016" {
106106
TestObjectMatch "Registered In DNS" "True"
107107
TestObjectMatch "Packets Received Discarded" 0 -WriteType "Green"
108108

109-
$Script:ActiveGrouping.Count | Should -Be 16
109+
$Script:ActiveGrouping.Count | Should -Be 17
110110
}
111111

112112
It "Display Results - Frequent Configuration Issues" {

Diagnostics/HealthChecker/Tests/HealthChecker.E19.Main.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Describe "Testing Health Checker by Mock Data Imports" {
112112
TestObjectMatch "Registered In DNS" "True"
113113
TestObjectMatch "Packets Received Discarded" 0 -WriteType "Green"
114114

115-
$Script:ActiveGrouping.Count | Should -Be 16
115+
$Script:ActiveGrouping.Count | Should -Be 17
116116
}
117117

118118
It "Display Results - Frequent Configuration Issues" {
@@ -234,7 +234,7 @@ Describe "Testing Health Checker by Mock Data Imports" {
234234

235235
TestObjectMatch "Sleepy NIC Disabled" "True"
236236

237-
$Script:ActiveGrouping.Count | Should -Be 18
237+
$Script:ActiveGrouping.Count | Should -Be 19
238238
}
239239

240240
It "Display Results - Security Settings" {

Security/src/ExchangeExtendedProtectionManagement/DataCollection/Get-ExchangeServerIPs.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function Get-ExchangeServerIPs {
3838

3939
$IpsFound = $false
4040
# TODO: Refactor Get-AllNicInformation function to get rid of the duplicate ComputerName / FQDN logic
41-
$HostNetworkInfo = Get-AllNicInformation -ComputerName $Server.FQDN
41+
$HostNetworkInfo = (Get-AllNicInformation -ComputerName $Server.FQDN).Adapters
4242
if ($null -ne $HostNetworkInfo) {
4343
if ($null -ne $HostNetworkInfo.IPv4Addresses) {
4444
foreach ($address in $HostNetworkInfo.IPv4Addresses) {

Shared/Get-AllNicInformation.ps1

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function Get-AllNicInformation {
1515
)
1616
begin {
1717

18+
#cspell:ignore Lbfo
1819
# Extract for Pester Testing - Start
1920
function Get-NicPnpCapabilitiesSetting {
2021
[CmdletBinding()]
@@ -125,6 +126,9 @@ function Get-AllNicInformation {
125126

126127
$nicObjects = New-Object 'System.Collections.Generic.List[object]'
127128
$networkAdapterConfigurations = $null
129+
$getNetLbfoTeam = $null
130+
$getNetAdapter = $null
131+
$newCimSession = $null
128132
}
129133
process {
130134
if ($WmiObject) {
@@ -138,6 +142,41 @@ function Get-AllNicInformation {
138142
Invoke-RemotePipelineHandler -Result ([ref]$networkAdapterConfigurations)
139143
}
140144

145+
if (($ComputerName).Split(".")[0] -ne $env:COMPUTERNAME) {
146+
try {
147+
$newCimSession = New-CimSession -ComputerName $ComputerName -ErrorAction Stop
148+
} catch {
149+
Write-Verbose "Failed to get the Cim Session for the computer. Inner Exception $_"
150+
Invoke-CatchActionError $CatchActionFunction
151+
}
152+
}
153+
154+
if ((($ComputerName).Split(".")[0] -ne $env:COMPUTERNAME) -and $null -eq $newCimSession) {
155+
Write-Verbose "Failed to get the Cim Session for a non-local computer, can't get the additional adapter information."
156+
} else {
157+
$params = @{
158+
ErrorAction = "Stop"
159+
}
160+
161+
if ($null -ne $newCimSession) {
162+
$params.Add("CimSession", $newCimSession)
163+
}
164+
165+
try {
166+
$getNetLBfoTeam = Get-NetLbfoTeam @params
167+
} catch {
168+
Write-Verbose "Failed to run Get-NetLbfoTeam. Inner Exception: $_"
169+
Invoke-CatchActionError $CatchActionFunction
170+
}
171+
172+
try {
173+
$getNetAdapter = Get-NetAdapter @params
174+
} catch {
175+
Write-Verbose "Failed to run Get-NetAdapter. Inner Exception: $_"
176+
Invoke-CatchActionError $CatchActionFunction
177+
}
178+
}
179+
141180
foreach ($networkConfig in $NetworkConfiguration) {
142181
$dnsClient = $null
143182
$rssEnabledValue = 2
@@ -151,11 +190,24 @@ function Get-AllNicInformation {
151190
$ipv6Enabled = $false
152191
$isRegisteredInDns = $false
153192
$dnsServerToBeUsed = $null
193+
$isTeamedNic = $false
194+
$teamedMembers = $null
154195

155196
if (-not ($WmiObject)) {
156197
Write-Verbose "Working on NIC: $($networkConfig.InterfaceDescription)"
157198
$adapter = $networkConfig.NetAdapter
158199

200+
if ($null -ne $getNetLbfoTeam) {
201+
foreach ($team in $getNetLbfoTeam) {
202+
if ($team.Name -eq $adapter.Name) {
203+
Write-Verbose "NIC Appears to be a teamed NIC"
204+
$isTeamedNic = $true
205+
$teamedMembers = $team.Members
206+
break
207+
}
208+
}
209+
}
210+
159211
if ($adapter.DriverFileName -ne "NdIsImPlatform.sys") {
160212
$nicPnpCapabilitiesSetting = $null
161213
Get-NicPnpCapabilitiesSetting -NicAdapterComponentId $adapter.DeviceID |
@@ -312,13 +364,20 @@ function Get-AllNicInformation {
312364
RegisteredInDns = $isRegisteredInDns
313365
DnsServer = $dnsServerToBeUsed
314366
DnsClient = $dnsClient
367+
IsTeamedNic = $isTeamedNic
368+
TeamedMembers = $teamedMembers
315369
})
316370
}
317371
}
318372
end {
373+
$obj = [PSCustomObject]@{
374+
Adapters = [array]$nicObjects
375+
GetNetAdapter = $getNetAdapter
376+
GetNetLbfoTeam = $getNetLbfoTeam
377+
}
319378
Write-Verbose "Found $($nicObjects.Count) active adapters on the computer."
320379
Write-Verbose "Exiting: $($MyInvocation.MyCommand)"
321-
return $nicObjects
380+
return $obj
322381
}
323382
}
324383

0 commit comments

Comments
 (0)