Skip to content

Instantly share code, notes, and snippets.

@krzydoug
Created August 18, 2020 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzydoug/1156562d099edb70f2a1aeb423ba0661 to your computer and use it in GitHub Desktop.
Save krzydoug/1156562d099edb70f2a1aeb423ba0661 to your computer and use it in GitHub Desktop.
$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.name successfully. -ForegroundColor Cyan
}
else
{
write-host Setting MAC address $newmac on $nic.name 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment