Display host name and raw MAC Address

Welcome Forums General PowerShell Q&A Display host name and raw MAC Address

This topic contains 2 replies, has 2 voices, and was last updated by

3 years, 4 months ago.

  • Author
  • #30772

    Points: 0
    Rank: Member

    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?


  • #30775

    Points: 0
    Rank: Member

    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

  • #30776

    Points: 0
    Rank: Member

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

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


The topic ‘Display host name and raw MAC Address’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort