none
How to get MAC address of remote machine?

    Question

  • I have a network (LAN), and I want to collect all the MAC addresses into one place.  I don't want to log onto each workstation and run getmac, nor do I want to Enter-PSSession for each w/s.

    Now, all I want is the mac address, nothing else.  The following works on my local machine:

    $m = getmac | Select-String -NotMatch 'Media disconnected' | Select-String '..-..-..-..-..-..'
    $matches.Values
    
    

    As you can see, I only want the MAC address of the connected media, so using WMI isn't an option (I don't think).

    The problem is, when I put this command into a scriptblock and run it with Invoke-Command, it returns nothing.  The same thing done interactively in a PSSession works as expected.

    Can anyone help me to make this work?


    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"
    Thursday, October 27, 2011 8:00 AM

Answers

  • Why do you want to use ps remoting for this?

    getmac can also query remote systems with the /s switch.

    Another hint, try

     getmac /fo csv | convertfrom-csv

    this way you get an "object" and you can use the select-object and where-object cmdlets

    for example

    getmac /s $remotesystemname /fo csv | Convertfrom-Csv | Where-Object {$_."Transport Name" -ne "Disconnected"}

    Be aware that the output of getmac is language specific. When you run getmac on a German OS for example you get the output in German and than it says "nicht verbunden" instead of disconnected.

     

     



    • Edited by Thomas Biebl Thursday, October 27, 2011 9:10 AM
    • Marked as answer by Bigteddy Thursday, October 27, 2011 9:35 AM
    Thursday, October 27, 2011 9:08 AM

All replies

  • Why do you want to use ps remoting for this?

    getmac can also query remote systems with the /s switch.

    Another hint, try

     getmac /fo csv | convertfrom-csv

    this way you get an "object" and you can use the select-object and where-object cmdlets

    for example

    getmac /s $remotesystemname /fo csv | Convertfrom-Csv | Where-Object {$_."Transport Name" -ne "Disconnected"}

    Be aware that the output of getmac is language specific. When you run getmac on a German OS for example you get the output in German and than it says "nicht verbunden" instead of disconnected.

     

     



    • Edited by Thomas Biebl Thursday, October 27, 2011 9:10 AM
    • Marked as answer by Bigteddy Thursday, October 27, 2011 9:35 AM
    Thursday, October 27, 2011 9:08 AM
  • This, however, does work on a PS2.0 machine:

    $sb={
    $m = getmac | Select-String -NotMatch 'Media disconnected' | Select-String '..-..-..-..-..-..'
    $m -match '..-..-..-..-..-..' | Out-Null
    $matches.Values
    }
    
    icm -cn pc11 -scr $sb
    
    

    But the following code will work on PS3.0, but not PS2.0.  Can anyone verify this?

    $m = getmac | Select-String -NotMatch 'Media disconnected' | Select-String '..-..-..-..-..-..'
    $matches.Values


    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"
    Thursday, October 27, 2011 9:09 AM
  • Thanks, Thomas, I didn't know one could query remote systems with getmac.  And also thanks for the good tips.
    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"
    Thursday, October 27, 2011 9:36 AM