In my Realtek USB GbE Family Controller adapter, in advanced properties, I can set a value in “Network address”, forcing the adapter to have another MAC Address.
Is it possible to do this with a PowerShell script or command?
Not sure that is correct. The MAC address is a permanent read-only value set by the manufacturer to provide a unique identifier to a piece of hardware. Most likely you are setting a MAC address spoofing value that the RealTek software sends when communicating with other devices, but it does not change the actual MAC value.
As far as setting that value with Powershell, it’s most likely in the Registry under the vendor like Software\RealTek. You should just search for the MAC address set and find it.
I need that a notebook when connected to a docking pass through a specific MAC address, in order to apply some configurations. This is working but when the adapter driver is updated, this setting is lost. I need a way to set-up this value using a script and not by working in each corporate notebook.
The best way I’ve found is to search for the appropriate adapter by name. The following code will set the MAC on an Intel NIC. I’ve set it to warn if more than one NIC matches and in that case just refine your search term. I may end up writing a function to make it easier to use. This was tested on an Intel 1219-LM and the property (named “Locally Administered Address” in this case) was updated in device manager instantly. I believe you need to disable/enable or reboot for it to take effect.
**** DISCLAIMER ****
Editing the registry directly can have serious, unexpected consequences that can prevent the system from starting and require that you reinstall Windows. It is your responsibility to back up and protect your computer/registry. If you are not familiar with making modifications to the registry, I suggest you do not proceed.
OK with that out of the way, you can just set your searchterm and your MAC, and this should do the rest.
$searchterm = 'intel'
$newmac = 'A0B1C2D3E4F5'
$path = 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}'
Push-Location $path
$nic = Get-ChildItem -ea SilentlyContinue | Get-ItemProperty | where driverdesc -like "*$searchterm*"
switch($nic.pspath.count)
{
1 {
Write-host Setting MAC address on adapter $nic.DriverDesc to $newmac -ForegroundColor Green
set-itemproperty -Path $nic.PSPath -Name NetworkAddress -Value $newmac -Type String
if((Get-ItemProperty -Path $nic.PSPath -Name NetworkAddress).NetworkAddress -eq $newmac)
{
write-host MAC address $newmac has been set on $nic.driverdesc successfully. -ForegroundColor Cyan
}
else
{
write-host Setting MAC address $newmac on $nic.driverdesc failed -ForegroundColor Red
}
}
{$_ -gt 1} {
Write-warning "More than one NIC matched '$searchterm' nPlease refine the search term."
}
default {Write-Host No NIC matched $searchterm -ForegroundColor DarkCyan}
}
Pop-Location
Note there should be backticks in front of each single quote around $searchterm and one before nPlease. The forum is not playing nice with them. I’ve also made a gist for convenience.
It’s most likely based on the adapter. See if there is an association with Get-NetworkAdapter or WMI Win32_NetworkAdapter. For instance, 16 refers to the device ID, so you would have to find the adapter to find the registry key if you can’t use something generic like ‘intel’ as Doug had done.
I deployed the script remotely with PDQ Deploy and it works!!! It helps that we have a corporate policy of brand and model so all of our docking stations have the same adapter.