0

I use PowerShell to determine the mac-addresses for Ethernet as well as the WiFi... the mac-address will be used for verification purposes..

Per command I would love to retrieve only the value not the key and the value… that I can store and verify the retrieved string with the known string.

Example:

Get-NetAdapter -Name "Wi-fi" | Format-List -Property MacAddress

will return the MacAddress : XX-XX-XX-XX-XX-XX

What I want is only XX-XX-XX-XX-XX-XX

Is there any filer I can apply without code ..workarounds….

2 Answers 2

1

Format-List is not needed, just access the property directly. Like so,

(Get-NetAdapter -name "wi-fi").macaddress
01-23-45-67-89-AB

Sometimes an intermediate variable is needed instead of the shorthand above. Like so,

$wifi = Get-NetAdapter -name "wi-fi"
$wifi.MacAddress
01-23-45-67-89-AB

In case you got several adapters, Select-Object can be used to expand the desired property. Like so,

Get-NetAdapter | ? { $_.status -eq "up" } | Select-Object -ExpandProperty macaddress
01-23-45-67-89-AB
01-23-45-67-89-CD
Sign up to request clarification or add additional context in comments.

2 Comments

I tried to verify your solution, but it doesn't answer OP's entire question. the mac-addresses for Ethernet as well as the WiFi. Wi-Fi works great, but Ethernet does not with this solution.
The shortcut from first will equally work with the last example (Get-NetAdapter |? Status -eq 'Up').MacAddress (+1)
1

Not to ruin vonPryz partially acceptable answer, but:

(get-wmiobject win32_networkadapter -Filter "AdapterType LIKE 'Ethernet 802.3'") | select -expand macaddress

This will give you all mac-adresses on your computer.

Or in a comma seperated list:

(Get-WmiObject win32_networkadapterconfiguration -ComputerName $env:COMPUTERNAME | Where{$_.IpEnabled -Match "True"} | Select-Object -Expand macaddress) -join ","

Or in a new-Line list:

(Get-WmiObject win32_networkadapterconfiguration -ComputerName $env:COMPUTERNAME | Where{$_.IpEnabled -Match "True"} | Select-Object -Expand macaddress) -join "`r`n"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.