Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.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

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
获取Windows计算机网卡速度的PowerShell脚本_Windows_Powershell_Wmi - Fatal编程技术网

获取Windows计算机网卡速度的PowerShell脚本

获取Windows计算机网卡速度的PowerShell脚本,windows,powershell,wmi,Windows,Powershell,Wmi,获取特定Windows计算机网卡运行速度的PowerShell脚本是什么 我知道这可以通过基于WMI查询的语句来完成,并且在我完成后会发布一个答案。基本命令是 Get-WmiObject -ComputerName 'servername' -Class Win32_NetworkAdapter | ` Where-Object { $_.Speed -ne $null -and $_.MACAddress -ne $null } | ` Format-Table -Proper

获取特定Windows计算机网卡运行速度的PowerShell脚本是什么

我知道这可以通过基于WMI查询的语句来完成,并且在我完成后会发布一个答案。

基本命令是

Get-WmiObject -ComputerName 'servername' -Class Win32_NetworkAdapter | `
    Where-Object { $_.Speed -ne $null -and $_.MACAddress -ne $null } | `
    Format-Table -Property SystemName,Name,NetConnectionID,Speed
请注意,ComputerName参数采用一个数组,因此,如果您有权限,可以对多台计算机运行此参数。将格式表属性列表替换为****以获得更全面的可用属性列表。您可能希望对这些属性进行筛选,以删除您不感兴趣的条目

使用内置的字节乘数后缀(MB、GB等)也可以根据您的需要提高速度的可读性。您可以将其指定为格式表-属性数组上的哈希表项,例如

Format-Table -Property NetConnectionID,@{Label='Speed(GB)'; Expression = {$_.Speed/1GB}}

我的当前版本,取出蓝牙和无线网卡(使用powershell-file script.ps1运行):


从Windows 8/Server 2012开始,您可以尝试使用
获取NetAdapter
和一些更专门的命令,如
获取NetAdapterAdvancedProperty

您还可以使用更全面的WMI类
MSFT\u NetAdapter
创建自定义输出<代码>MSFT_NetAdapter如下所述:

下面是一个命令,用于列出本地计算机上已启用(状态2)、已连接(OperationalStatusDownMediaDisconnected$false)、802.3有线(NdisPhysicalMedium 14)、非虚拟适配器的速度和其他属性:

Get-WmiObject -Namespace Root\StandardCimv2 -Class MSFT_NetAdapter | `
  Where-Object { $_.State -eq 2 -and $_.OperationalStatusDownMediaDisconnected -eq $false -and `
                 $_.NdisPhysicalMedium -eq 14 -and $_.Virtual -eq $false } | `
  Format-Table Name,Virtual,State,NdisPhysicalMedium, `
  @{Label='Connected'; Expression={-not $_.OperationalStatusDownMediaDisconnected}}, `
  @{Label='Speed(MB)'; Expression = {$_.Speed/1000000}}, `
  FullDuplex,InterfaceDescription

回答得好!我将删除
-ne$null
部分。实际上,Win32\u NetworkAdapter类返回了很多条目,请查看。我正在使用-ne$null筛选条目,这样我就可以看到真实物理卡的实际条目,但您可以根据需要进行调整。[System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()仅对本地计算机起作用。我想Jay是说过滤器可以简化为
其中{$\.Speed-和$\.MACAddress}
。只要不是0或$false,简化的谓词就可以正常工作。此外,您可能希望过滤掉0的值。显然,它也会允许0的值。这应该是唯一的区别。
Get-WmiObject -Namespace Root\StandardCimv2 -Class MSFT_NetAdapter | `
  Where-Object { $_.State -eq 2 -and $_.OperationalStatusDownMediaDisconnected -eq $false -and `
                 $_.NdisPhysicalMedium -eq 14 -and $_.Virtual -eq $false } | `
  Format-Table Name,Virtual,State,NdisPhysicalMedium, `
  @{Label='Connected'; Expression={-not $_.OperationalStatusDownMediaDisconnected}}, `
  @{Label='Speed(MB)'; Expression = {$_.Speed/1000000}}, `
  FullDuplex,InterfaceDescription