Created
August 18, 2020 17:18
-
-
Save krzydoug/1156562d099edb70f2a1aeb423ba0661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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