Tuesday, April 5, 2016

Physical network adapter MAC address information - PowerShell Report

Scenario:
You have new or existing network with no or outdated inventory of server-to-switch port connectivity information. Your Network engineer is going to discover server-to-switch port connectivity information remotely using MAC addresses of physical network adapters.
PowerShell script will convert a Windows MAC address to a Cisco friendly MAC address.
Physical network adapter vendors: Intel, Broadcom (acquired by QLogic)

Requirements:
Active Directory domain joined servers based on Windows Server 2012+
Domain account that is member of local administrator group on servers (such as Domain Admin)

PowerShell script
which gathers all MAC addresses of physical network adapters on servers:

$cred Get-Credential
$serverlist = (Import-CSV ServerList.csv).Servers
$Report @()
foreach ($server in $serverlist) {
$CimSession = New-CimSession -Credential $cred -ComputerName $server
Get-NetAdapter -CimSession $CimSession | where {$_.InterfaceDescription -match "broadcom*|intel*|Qlogic*"} | Sort-Object Name | foreach {
$Properties = @{
ServerName=$server;
NICName=$_.name;
Description=$_.InterfaceDescription;
MACAddress=($_.MacAddress -replace "-","").insert(4,".").insert(9,".").ToLower();
LinkSpeed=$_.LinkSpeed;
Status=$_.Status;}
$Report += New-Object PSObject -Property $Properties}
}
$Report | Export-CSV MACReport.csv -NoTypeInformation


where CSV-file content of ServerList.csv just like:

Servers
Server1
Server2
Server3
Server4
Server5