Script to change MAC Address on specific adapter

Hi experts:

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?

Thank you very much.

J.C.

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.

Thank you Rob, I am aware of that.

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 data is stored in the registry as Rob suggests, but they are located in one of the numbered subfolders at the following path

'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}'

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.

https://gist.github.com/krzydoug/1156562d099edb70f2a1aeb423ba0661

Thank you very much Doug, this is exactly what I was looking for.

Odd, I cannot see Doug(h)'s post that is being reference.

It disappeared because I fixed a typo… you know.

Me neither! I was going to copy to test it, and it just disappeared…

$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

backticks are not working on here, refer to the gist

https://gist.github.com/krzydoug/1156562d099edb70f2a1aeb423ba0661

My other post was more complete, I’m just waiting for mods to reinstate it. It had a disclaimer about modifying the registry as well.

I found that the network address value is saved in this key:

HKLM - System - CurrentControlSet - Control - Class - {4d36e972-e325-11ce-bfc1-08002be10318] - 0016

I would not need a PS script if this was a fixed location, but unfortunately the last 4 digits change…

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.

My script searches for it by name.

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.

Thank you Doug and Rob for your time.

J.C.