'Can the -eq function compare against a variable

It appears that -eq can only compare against a literal. I am trying to compare against a variable like this. This code does not work

> $macaddr = ((getmac /v /fo csv | findstr ASIX) -split "," )[2]
> $echo $macaddr
"00-01-02-03-04-05"
> $adapter = Get-NetAdapter | ? {$_.MacAddress -eq $macaddr}
> echo $adapter
>

If I change the comparison to a literal, it appears to work fine.

> $adapter = Get-NetAdapter | ? {$_.MacAddress -eq "00-01-02-03-04-05"}
> echo $adapter
Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet 3                ASIX AX88179 USB 3.0 to Gigabit Ethe...      12 Up           00-01-02-03-04-05       100 Mbps

How should I handle the comparison?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source