List of MAC addresses for 10 machines

0

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.

linud

Posted 2014-06-27T06:44:11.783

Reputation: 25

Answers

2

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
    

Richard

Posted 2014-06-27T06:44:11.783

Reputation: 8 152

0

There's a cmdlet for that:

Get-NetAdapter -Physical will give you information on your local interfaces.

If you add the -CimSession parameter (Get-NetAdapter -Physical -CimSession), you can connect to a server by its ComputerName.

You end up with: Get-NetAdapter -Physical -CimSession "ComputerName, ComputerName", where you can also fill ComputerName with a variable containing the names of the servers you will be working with. Separate multiple computer names with a ,.

You will find the PowerShell Integrated Scripting Environment by searching for powershell_ise.exe at the root of your Boot Volume (usually C:) in Windows Explorer :). You'll probably want to right-click and run it as Administrator ;).

Why should you use CIM? Some reasons to attempt to persuade you:

goals for new CIM Cmdlets

  • Rich PowerShell experience. Make CIM a first class citizen of PS, addressing usability concerns and user feedback for WMI and WsMan Cmdlets.

  • Standard compliance. With so much focus on standards, our goal is to make PowerShell the best platform for managing Windows and Non-Windows. New CIM Cmdlets should be able to manage any CIM + WsMan compliant endpoint, including Windows.

  • Support for down-level machines. We understand that there are more down-level servers in a datacenter than there would be Windows Server 2012 for some time to come. We want to make sure same set of Cmdlets can be used to manage down-level Windows as well.

You can read more here!

One more thing: You'll need to be using Windows PowerShell 3.0 or above for this to work; to learn how to upgrade your version of Windows PowerShell from Windows 7 click here.

cody.codes

Posted 2014-06-27T06:44:11.783

Reputation: 1 172

No problem. Feel free to mark my answer as useful. If you're getting into PowerShell you might be interested in reading this book. Happy travels!

– cody.codes – 2014-06-27T13:42:49.493