PowerShell for Windows Admins

Aug 19 2011   1:10PM GMT

Testing MAC address changes

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


My recent post on using MSNdis_EthernetCurrentAddress to get the MAC address may have had you saying so what because I can do this

Get-WmiObject -Class Win32_NetworkAdapter -ComputerName “.” | select Name, MACAddress

However, there is another class MSNdis_EthernetPermanentAddress which shows the permanent address. This means we can see if the MAC address has been changed. This does happen in a few places including NLB.

function convert-macaddresstostring{            
 param ($address)            
 $values = @()            
 $address |             
 select -ExpandProperty Address |            
 foreach {            
  $values += ([convert]::ToString($_,16)).ToUpper().PadLeft(2,"0")            
 $values -join "-"            
function test-macaddresschange {            
Get-WmiObject -Namespace root\wmi -Class MSNdis_EthernetCurrentAddress `
-ComputerName $computer |            
foreach {            
  $currentmac = convert-macaddresstostring $($_.NdisCurrentAddress)            
  $perm = Get-WmiObject -Namespace root\wmi  `
  -Class MSNdis_EthernetPermanentAddress -ComputerName $computer `
  -Filter "InstanceName='$($_.InstanceName)'"            
  $permanentmac = convert-macaddresstostring $($perm.NdisPermanentAddress)            
  New-Object -TypeName PSobject -Property @{            
  Computer = $_.__SERVER            
  Adapter = $_.InstanceName            
  CurrentMACAddress = $currentmac            
  PermanentMACAddress = $permanentmac            

You should recognize this from the previous post. We use MSNdis_EthernetCurrentAddress  and loop through the adapters. Then MSNdis_EthernetPermanentAddress  is used to get the permanent MAC address of the instance. Instance name is used as a filter. The conversion of the MAC address from integer array to string is pushed into its own function.

The output object is altered to show current and permanent addresses

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: