GetMac.exe

Display the Media Access Control (MAC) address and list of network protocols associated with each address for all network cards in each computer, either locally or across a network.

Syntax
      GETMAC [/s Computer [/u Domain\User [/p Password]]]
         [/fo {TABLE|LIST|CSV}] [/nh] [/v]

Key
   /s Computer     The name or IP address of a remote computer
                  (do not use backslashes). Default = local computer.

   /u Domain\User  Run the command with the account permissions of the
                   user specified. Default = the currently logged on user.

   /p Password     The password of the user account that is specified in the /u parameter.

   /fo { TABLE | LIST | CSV } 
                   Format the output. Default = TABLE.

   /nh   Omit the header row from the displayed driver information.
         Valid when the /fo parameter is set to TABLE or CSV.

   /v    Display verbose information.

   /?    Display Help. 

Examples

Show all MAC addresses in Table output:

getmac /fo table /nh /v

Show MAC addresses on server64:

getmac /s server64

Show MAC addresses on server64 and authenticate as a different user:

getmac /s server64 /u ss64Dom\user583

Export a verbose listing of MAC addresses to a CSV file:

getmac /v /fo csv > T:\macaddresses.csv

PowerShell script to get the Mac address of the current machine:

$Mac = getmac /fo csv | ConvertFrom-Csv

PowerShell script to collect Mac addresses for multiple machines by calling GetMac:

# Create empty hash table
$macHash=@{}
# Load a list of machine names
$servers=get-content c:\batch\servers.txt
foreach ($server in $servers) {
   if (Test-Connection $server -quiet) {   # if it responds to a Ping
      # Call the GetMac utility
      $getmac=getmac /nh /fo csv /s $server
      $macAddresses=$getmac -split ","
      $interface = 1
      $macAddresses | foreach {
         if ($_ -ne ""){
            # check for a '-' to see if we have a mac address
            if ($_.substring(3,1) -eq "-") {
               # Remove quotes
               $addr = $_.replace("""","")
               $adapter = $interface/2
               Echo "$server  Adapter:$adapter  $addr"
               # Save in the hash variable
               $macHash.add("$server Adapter:$adapter",$addr)
            }
         }
      $interface += 1
      }
   }
}
# Export the hash table to a spreadsheet
$macHash.GetEnumerator() | select name, value | Sort-Object Name | Export-CSV -Path "c:\batch\macaddresses.csv" -NoTypeInformation

“I am the literary equivalent of a Big Mac and Fries” ~ Stephen King (Writer, best known for horror novels.)

Related commands

DevCon - Device Manager Command Line Utility.
WMI : Win32_NetworkAdapter
PowerShell: Get-NetAdapter - Get the basic network adapter properties.


 
Copyright © 1999-2024 SS64.com
Some rights reserved