Get MAC Addresses through PowerShell
Posted on PowerShell, Scripting
We needed to get the MAC addresses for the network team and I didn’t have a script for it in my library. We already had the list of servers we need, so I used that to query WMI and return the MAC on the adapters that would be connected to the network.
$Servers = Import-Csv c:\Temp\servers.csv
foreach ($Server in $Servers) {
$NetAdapter = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Server.Name -Filter "IpEnabled = TRUE"
foreach ($Adapter in $NetAdapter) {
$Name = $Server.Name
$MAC = $Adapter.MacAddress
Write-Host "$Name - $MAC"
}
}