Powershell Win32_NetworkAdapterConfiguration 没有“看到”PPP 适配器

Powershell Win32_NetworkAdapterConfiguration 没有“看到”PPP 适配器

我正在尝试获取 PPP VPN 网络连接的 IP,但 Win32_NetworkAdapterConfiguration 似乎没有“看到”它。

如果我使用脚本查询所有适配器,它将看到除 PPP VPN 适配器之外的所有内容。是否有特定的过滤器或我需要启用的东西,或者我需要不同的类吗?

我的脚本:

$colItems = Get-wmiobject Win32_NetworkAdapterConfiguration
foreach ($objItem in $colItems) {
    Write-Host Description: $objItem.Description
    Write-Host IP Address: $objItem.IPAddress
    Write-Host ""
}

脚本输出:

Description: WAN Miniport (SSTP)
IP Address:

Description: WAN Miniport (IKEv2)
IP Address:

Description: WAN Miniport (L2TP)
IP Address:

Description: WAN Miniport (PPTP)
IP Address:

Description: WAN Miniport (PPPOE)
IP Address:

Description: WAN Miniport (IPv6)
IP Address:

Description: WAN Miniport (Network Monitor)
IP Address:

Description: Intel(R) PRO/Wireless 3945ABG Network Connection
IP Address: 192.168.2.5

Description: WAN Miniport (IP)
IP Address:

ipconfig /all 输出:

PPP adapter My VPN:

   Connection-specific DNS Suffix  . : 
   Description . . . . . . . . . . . : My VPN
   Physical Address. . . . . . . . . : 
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 10.1.8.12(Preferred) 
   Subnet Mask . . . . . . . . . . . : 255.255.255.255
   Default Gateway . . . . . . . . . : 0.0.0.0
   DNS Servers . . . . . . . . . . . : 10.1.1.3
                                       10.1.1.2
   Primary WINS Server . . . . . . . : 10.1.1.2
   Secondary WINS Server . . . . . . : 10.1.1.3
   NetBIOS over Tcpip. . . . . . . . : Enabled



Wireless LAN adapter Wireless Network Connection:

   Connection-specific DNS Suffix  . : Belkin
   Description . . . . . . . . . . . : Intel(R) PRO/Wireless 3945ABG Network Connection
   Physical Address. . . . . . . . . : 00-3F-3C-22-22-22
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.2.5(Preferred) 
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : 25 May 2010 20:33:19
   Lease Expires . . . . . . . . . . : 22 May 2020 20:33:17
   Default Gateway . . . . . . . . . : 192.168.2.1
   DHCP Server . . . . . . . . . . . : 192.168.2.1
   DNS Servers . . . . . . . . . . . : 192.168.2.1
   NetBIOS over Tcpip. . . . . . . . : Enabled

提前致谢,

答案1

我知道这是一个非常古老的话题,但我仍然会发布我管理它的方式,以便它可以帮助像我这样的人,因为我找不到现成的解决方案。

它会循环遍历多个主机及其 NIC。它会显示所有 NIC IP,但不会显示默认 IP。

Get-wmiobject Win32_NetworkAdapterConfiguration -filter IPEnabled=TRUE -computername localhost,127.0.0.1 | ForEach-Object -Process {
    Write-Host Server: $_.__SERVER
    Write-Host Adapter name: $_.Description
    Write-Host IP Addresses: $_.IPAddress
    Write-Host ""
}

答案2

这是一个漏洞该问题在 Vista 中存在,但尚未通过 Windows 7 或 Windows 8 得到修复。您必须直接从 Powershell 调用 .NET API 来获取此信息。

$nics = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()
foreach ($nic in $nics) {
    write-host $nic.name
    $props = $nic.GetIPProperties()
    $addresses = $props.UnicastAddresses
    foreach ($addr in $addresses) {
        write-host "IP Address: $($addr.Address.IPAddressToString)"
        write-host "IPv4 Mask: $($addr.IPv4Mask.IPAddressToString)"
    }
    write-host "Gateway: $($props.GatewayAddresses.Address.IPAddressToString)"
    write-host "DNS Server(s): $($props.DnsAddresses.IPAddressToString)"
    write-host ""
}

也可以看看NetworkInterface 类文档

答案3

改用 MSFT_NetIPAddress 类。

Powershell 示例:

gwmi MSFT_NetIPAddress -Namespace 'root/standardcimv2' | format-list -Property InterfaceAlias,IPAddress

相关内容