Created
October 23, 2024 07:03
-
-
Save Axlfc/d0359fc3dac88edb541af4c04752cfe0 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
function Get-EthernetMacAddress { | |
try { | |
# Get network adapters | |
$adapters = Get-NetAdapter | Where-Object { $_.InterfaceDescription -like '*Ethernet*' } | |
if ($adapters.Count -eq 0) { | |
Write-Error "No Ethernet adapter found." | |
return $null | |
} | |
# Get MAC address of the first Ethernet adapter found | |
$ethernetAdapter = $adapters[0] | |
$macAddress = $ethernetAdapter.MacAddress | |
return $macAddress | |
} catch { | |
Write-Error "Failed to retrieve Ethernet adapter MAC address." | |
} | |
} | |
$ethernetMacAddress = Get-EthernetMacAddress | |
if ($ethernetMacAddress) { | |
Write-Host "Ethernet MAC Address: $ethernetMacAddress" | |
# Optionally, you can use the retrieved MAC address here for further processing | |
} else { | |
Write-Host "Ethernet MAC address could not be retrieved." | |
} | |
$Age = Read-Host "Ethernet MAC Address" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment