Categories

Testing MAC address changes

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 {            
param(            
 [string]$computer="."            
)            
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 recognise 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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>