# Get all Hyper-V SET teams $teams = Get-VMSwitchTeam # Check if there are any teams if ($teams.Count -eq 0) { Write-Output "OK: No Team available" exit 0 } foreach ($team in $teams) { $teamName = $team.Name $teamAdapters = Get-VMSwitchTeam -Name $teamName # Check if there are any adapters in the team if ($teamAdapters.NetAdapterInterfaceDescription.Count -eq 0) { Write-Output "CRITICAL: $teamName down - All Adapters are down" exit 2 } else { # Initialize a counter for adapters that are UP $upCount = 0 $totalAdapters = $teamAdapters.NetAdapterInterfaceDescription.Count $exitCode = 0 $downAdapters = @() $speeds = @{} $differentSpeeds = $false # Check the status of each adapter using NetAdapterInterfaceDescription foreach ($adapter in $teamAdapters.NetAdapterInterfaceDescription) { $adapterStatus = Get-NetAdapter | Where-Object { $_.InterfaceDescription -eq $adapter } if ($adapterStatus.Status -eq "Up") { $upCount++ $speeds[$adapterStatus.Name] = $adapterStatus.LinkSpeed } else { $adapterName = Get-NetAdapter | Where-Object { $_.InterfaceDescription -eq $adapter } | Select-Object -ExpandProperty Name $downAdapters += $adapterName $exitCode = 1 } } # Check for different link speeds $uniqueSpeeds = $speeds.Values | Select-Object -Unique if ($uniqueSpeeds.Count -gt 1) { foreach ($adapter in $speeds.Keys) { Write-Output "WARNING: Different Speed $adapter, Link: $($speeds[$adapter])" } $differentSpeeds = $true $exitCode = 1 } # Output the result if ($upCount -eq $totalAdapters) { if ($differentSpeeds) { Write-Output "WARNING: $teamName $upCount Adapters of $totalAdapters are up" exit 1 } else { Write-Output "OK: $teamName $upCount Adapters of $totalAdapters are up" exit 0 } } elseif ($upCount -eq 0) { Write-Output "CRITICAL: $teamName down - Adapters down: $($downAdapters -join ', ')" exit 2 } else { Write-Output "WARNING: $teamName $upCount Adapters of $totalAdapters are up - Adapters down: $($downAdapters -join ', ')" exit $exitCode } } } # Default exit code if none of the above conditions are met Write-Host "UNKNOWN: Something wrent wrong" exit 3