What is the best way to get the network adapter with the lowest mac address? There are multiple network adapters named Intel(R) I210, just need the one with the lowest mac address.
$adapters = Get-NetAdapter -InterfaceDescription "Intel(R) I210*"
foreach ($adapter in $adapters) {
Write-Host $adapter.MacAddress
$lastMacSegment = $adapter.MacAddress.Split("-")[-1]
Write-Host "Last segment $lastMacSegment"
$dec = [Convert]::ToInt64($lastMacSegment, 16)
Write-Host $dec
}
???
CodePudding user response:
You can use Sort-Object
to sort the output from Get-NetAdapter
based on the .MacAddress
property and then get the lowest Mac Address based on that sort.
Get-NetAdapter "Intel(R) I210*" | Sort-Object MacAddress
For the lowest you would simply pipe it to Select-Object -First 1
.
I was previously using Sort-Object { [PhysicalAddress] $_.MacAddress }
however this is not even needed as Lee_Dailey pointed out.