Display host name and raw MAC Address

I am trying to enumerate all my NIC’s and display the name and raw MAC address to look something like:

Name MacAddress

NIC4 C8-1F-66-F7-1B-78
NIC3 C8-1F-66-F7-1B-77
NIC2 C8-1F-66-F7-1B-76
NIC1 C8-1F-66-F7-1B-75`

I am using the following
`# Get Adapter Name & MAC Address for each adapter and remove Dashes From MAC Address
$Adapters = Get-NetAdapter | Select Name, MACAddress | ForEach {$_.MacAddress -replace “-”,""}
but this only displays the raw MAC address.
Why is the Name stripped out when the ForEach cmdlet is run?


Your code will only emit the modified macaddress becasue you don’t include it in the foreach loop and output it.

You should do this

Get-NetAdapter | select Name, @{N=‘MacAddress’; E={$_.MacAddress -replace ‘-’,’’}}

Create a calculated field with select-object to perform the modification

Thanks Richard, worked great…you just missed the closing " at the end of the replace

Get-NetAdapter | select Name, @{N=‘MacAddress’; E={$_.MacAddress -replace ‘-’,""}}