mmm
mmm

Reputation: 51

Get only value, powerShell without key

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….

Upvotes: 0

Views: 1983

Answers (2)

Joel
Joel

Reputation: 6173

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"

Upvotes: 1

vonPryz
vonPryz

Reputation: 24071

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

Upvotes: 1

Related Questions