List of MAC addresses for 10 machines

I need to list of MAC addresses for a 10 computers having Windows 7 installed on them. These are named in a series like training1 - training10.

There IP addresses are on DHCP mode and update every week.

Any ideas on how do I script this on Windows? I know BASH scripting but windows powershell is new for me.


Solution 1:

Something like this should do it:

# An array of server names
$servers = 'comp1','comp2','comp3','comp4';
Get-WmiObject -computer $servers -class win32_networkadapter | 
    Where-Object AdapterType -eq 'Ethernet 802.3' | 
    Format-Table -auto __SERVER,Caption,ServiceName,AdapterType, MacAddress

with the result being something like (MAC addresses deliberately hidden):

__SERVER Description                                   ServiceName AdapterType    MacAddress
-------- -----------                                   ----------- -----------    ----------
COMP1    Microsoft Virtual Machine Bus Network Adapter netvsc      Ethernet 802.3 xx:xx:xx:xx:xx:xx
COMP2    Microsoft Virtual Machine Bus Network Adapter netvsc      Ethernet 802.3 xx:xx:xx:xx:xx:xx
COMP3    Realtek PCIe GBE Family Controller            RTL8167     Ethernet 802.3 xx:xx:xx:xx:xx:xx
COMP3    Microsoft Virtual Network Switch Adapter      VMSMP       Ethernet 802.3 xx:xx:xx:xx:xx:xx
COMP4    Realtek PCIe GBE Family Controller            RTL8167     Ethernet 802.3 xx:xx:xx:xx:xx:xx

Note:

  1. Some computers can have multiple NICs, and thus multiple MAC addresses.

  2. Not all NICs are physical. (Hyper-V virtualisation above.)

  3. When working from the command line I would use PSH aliases and positional parameters:

    gwmi -comp 'comp1','comp2','comp3','comp4' win32_networkadapter | ? AdapterType -eq 'Ethernet 802.3' | ft -auto __SERVER,Caption,ServiceName,AdapterType, MacAddress