Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 由IP标识的适配器的网络统计信息_Powershell - Fatal编程技术网

Powershell 由IP标识的适配器的网络统计信息

Powershell 由IP标识的适配器的网络统计信息,powershell,Powershell,我正在尝试使用powershell监视特定适配器的网络统计信息。监控过程本身运行良好,它基于Get-WMIOObject类Win32\u PerfFormattedData\u Tcpip\u网络接口 我的问题是根据IP地址选择要监视的正确接口。上面的代码不包含这些信息,所以我开始使用其他包含地址的命令,并试图找到关系。但目前没有成功 索引、名称、描述或任何其他字符串都不是唯一的。我很确定一定有什么东西,但我找不到/ 提前谢谢 编辑 我在这里发现了另一个与此完全相同的问题。它已经存在了几年,但仍

我正在尝试使用powershell监视特定适配器的网络统计信息。监控过程本身运行良好,它基于Get-WMIOObject类Win32\u PerfFormattedData\u Tcpip\u网络接口

我的问题是根据IP地址选择要监视的正确接口。上面的代码不包含这些信息,所以我开始使用其他包含地址的命令,并试图找到关系。但目前没有成功

索引、名称、描述或任何其他字符串都不是唯一的。我很确定一定有什么东西,但我找不到/

提前谢谢

编辑

我在这里发现了另一个与此完全相同的问题。它已经存在了几年,但仍然没有可靠的解决方案

编辑2

我创建了一个workarround,但没有直接访问Win32类。无论如何,我仍然对我最初的问题的解决方案感兴趣

$myIp = "192.168.1.101"

$myCurrentBytes = Get-NetAdapterStatistics | Where-Object -Property InterfaceAlias -eq `
                (Get-NetIPAddress | Where-Object -Property IPAddress -eq  $myIp | Select-Object -Property InterfaceAlias).InterfaceAlias `
                 | Select-Object -Property ReceivedBytes,SentBytes

$myCurrentKbytesDown = [math]::Round($myCurrentBytes.ReceivedBytes / 1024)
$myCurrentKbytesUp = [math]::Round($myCurrentBytes.SentBytes / 1024)

你需要使用过滤器

在这里:


这在Windows 2012上适用于我:

$myIp = "192.168.100.1"

$myCurrentBytes = Get-NetIPAddress $myIp | Get-NetAdapter | Get-NetAdapterStatistics | Select-Object -Property ReceivedBytes,SentBytes

$myCurrentKbytesDown = [math]::Round($myCurrentBytes.ReceivedBytes / 1024)
$myCurrentKbytesUp = [math]::Round($myCurrentBytes.SentBytes / 1024)

基本上,先找到IP地址,然后通过管道获取适配器,然后通过管道获取适配器统计信息。

如果添加相同类型的第二个适配器,您将从AdapterConfiguration获得例如Realtek PCIe GBE系列控制器2,从NetworkInterface获得Realtek PCIe GBE系列控制器2。我不确定是否理解您的意思。为什么要设置两个具有相同IP地址的接口?我不想在多个接口上使用相同的IP。您的代码使用描述/名称来标识适配器,但它也必须在具有多个相同类型适配器的计算机上工作。然后windows开始向每个适配器添加一个尾随数字,并且语法不同。
$myIp = "192.168.100.1"

$myCurrentBytes = Get-NetIPAddress $myIp | Get-NetAdapter | Get-NetAdapterStatistics | Select-Object -Property ReceivedBytes,SentBytes

$myCurrentKbytesDown = [math]::Round($myCurrentBytes.ReceivedBytes / 1024)
$myCurrentKbytesUp = [math]::Round($myCurrentBytes.SentBytes / 1024)