仅获取 IPv4 的 Powershell 脚本

Powershell script to get IPv4 only

我正在尝试仅从具有多个 IPv4 地址的计算机获取 IPv4。 输出也包含 IPv6,如下所示:

10.24.21.115
fe80::8029:4127:55a6:4328
192.168.0.2
fe80::ac59:de9a:c9db:b5d8

尝试过滤 $_.ipaddress - 不喜欢 "fe80*" 等等...

Get-WMIObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' | where { $_.ipaddress -notlike "fe80*" } | select-object -ExpandProperty IPAddress

预期输出为: 10.24.21.115, 192.168.0.2

怎么样

Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' |
  Select-Object -ExpandProperty IPAddress |
  Where-Object { $_ -match '(\d{1,3}\.){3}\d{1,3}' }