Convert XML string of bytes to MAC address

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 2 years ago.

  • Author
    Posts
  • #20565
    Profile photo of Mark E
    Mark E
    Participant

    Hi All

    I have the following xml element:

    class XmlElement
    {
    type = bytes
    #text = ABVdZBRW

    }

    I've been trying to convert the #text value to a MAC address, without much success. The closest I got was:

    $mac = "ABVdZBRW"
    $bytes = [System.Text.Encoding]::UTF8.GetBytes[$mac]
    [System.BitConverter]::ToString[$bytes]
    41-42-56-64-5A-42-52-57

    which is obviously wrong!

    The value [i]should[/i] convert to [b]00-15-5D-64-14-56[/b]... If it helps – the element is from a Legacy Network Adapter section in a Hyper-V virtual machine config file!

    Thanks!

    Mark

  • #20567
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    The problem is that you're treating that string as though it is UTF8. It's actually the MAC address in base64-encoded form:

    $base64 = "ABVdZBRW"
    $bytes = [System.Convert]::FromBase64String($base64)
    [System.BitConverter]::ToString($bytes)
    
  • #20568
    Profile photo of Mark E
    Mark E
    Participant

    Well – that is my ignorance showing through, now immortalized for all time on this message board! 🙂

    Your version works perfectly – thanks a lot!!!

    Mark

  • #20569
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Showing ignorance isn't a bad thing. 🙂 (See: [url="http://shop.oreilly.com/product/9780596518387.do"]Apprenticeship Patterns[/url] )

You must be logged in to reply to this topic.