Rem: Obtaining PCs’ MAC Addresses


I need to write an easily configurable script that obtains PCs' media access control (MAC) addresses. Sometimes the script will need to target the PCs in the top level of an organizational unit (OU). Other times the script will need to target all the PCs in the lower levels of an OU. Some PCs have more that one NIC and these additional MACs need to be captured as well. Do you have any suggestions on how I can write this script?

I recommend that you use Getmac to handle this task. This tool is part of Windows Server 2003. You can also find it in the Microsoft Windows XP Resource Kit and the Microsoft Windows 2000 Server Resource Kit.

The GetMACs.bat script demonstrates how you can use the Getmac utility to capture the data you need. Getmac's output contains a number of extraneous lines, so this script uses a chain of Find commands with the /V switch to filter out those lines. The script also uses the Dsquery utility to get the list of node names. Dsquery is part of Windows 2003. You can find it in the \%SystemRoot%\System32 folder.

You can download GetMACs.bat from the Windows Scripting Solutions Web site. Go to, enter 45509 in the InstantDoc ID text box, then click the hotlink.

To launch this script, you use the command


However, before you use it, you need to configure several variables. As Listing 2 shows, you first need to configure the target OU. Be sure to enclose the OU name in quotes. Next, you need to configure the target levels in the OU. You have two options: the OU's top level (set Scope to onelevel) or the OU's lower levels (set Scope to subtree). You then need to set the pathname to the output file. Once again, enclose the pathname in quotes. Finally, you need to configure the Universal Naming Convention (UNC) paths to the Dsquery and Getmac utilities unless these are installed locally on the node.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.