Skip to content

Instantly share code, notes, and snippets.

@scriptingstudio
Last active July 11, 2025 15:10
Show Gist options
  • Select an option

  • Save scriptingstudio/f87beb9d46cddf3a82609e2d1dbca04b to your computer and use it in GitHub Desktop.

Select an option

Save scriptingstudio/f87beb9d46cddf3a82609e2d1dbca04b to your computer and use it in GitHub Desktop.
Work around for a faulty network adapter
#Requires -RunAsAdministrator
<#
There are weird computers having physical netadapters without macaddress.
This script finds faulty netadapters and assigns a random macaddress to the adapter
#>
Get-NetAdapter -Physical -ErrorAction 0 | Where-Object {
$_.InterfaceDescription -notmatch 'Wireless|wi-fi|virt|Hyper-V' -and $_.MacAddress -eq '00-00-00-00-00-00'
} | ForEach-Object {
Write-Warning 'Faulty network adapter found!'
$newmac = (1..6 | ForEach-Object {
'{0:X}{1:X}' -f (Get-Random -Minimum 0 -Maximum 15),(Get-Random -Minimum 0 -Maximum 15)
}) -join '-'
Set-NetAdapter -Name $_.name -MacAddress $newmac -Confirm:$false -ErrorAction 0 #-NoRestart
'{0} :: {1}' -f $_.name, $newmac | Out-File -FilePath $PSScriptRoot\macaddress.txt -Encoding utf8 -Append -Force -ErrorAction 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment