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

发布于 2024-09-05 01:08:56 字数 98 浏览 6 评论 0原文

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

我知道这可以通过基于 WMI 查询的语句来完成,并且一旦我解决了就会发布答案。

What is the PowerShell script to get the speed a specific Windows machine's network card is running at?

I know this can be done with a WMI query based statement and will post an answer once I work it out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜夜流光相皎洁 2024-09-12 01:08:56

基本命令是

Get-WmiObject -ComputerName 'servername' -Class Win32_NetworkAdapter | `
    Where-Object { $_.Speed -ne $null -and $_.MACAddress -ne $null } | `
    Format-Table -Property SystemName,Name,NetConnectionID,Speed

请注意,ComputerName 参数采用一个数组,因此您可以在拥有权限的多台计算机上运行此命令。将 Format-Table 属性列表替换为 ***** 以获取更全面的可用属性列表。您可能希望过滤这些属性以删除您不感兴趣的条目。

根据您的需要,使用内置的字节乘数后缀(MB、GB 等)也将使速度更具可读性。您可以将其指定为 Format-Table -Property 数组上的哈希表条目,例如

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

A basic command is

Get-WmiObject -ComputerName 'servername' -Class Win32_NetworkAdapter | `
    Where-Object { $_.Speed -ne $null -and $_.MACAddress -ne $null } | `
    Format-Table -Property SystemName,Name,NetConnectionID,Speed

Note that the ComputerName parameter takes an array so you can run this against multiple computers provided you have rights. Replace the Format-Table property list with ***** to get a more comprehensive list of available properties. You might want to filter on these properties to get rid of entries you aren't interested in.

Using the built in byte Multiplier suffixes (MB, GB etc) would also make the speed more readable depending on your needs. You could specify this as a HashTable entry on the Format-Table -Property array e.g.

Format-Table -Property NetConnectionID,@{Label='Speed(GB)'; Expression = {$_.Speed/1GB}}
欲拥i 2024-09-12 01:08:56

从 Windows 8/Server 2012 开始,您可以尝试 Get-NetAdapter 和几个更​​专业的命令,例如 Get-NetAdapterAdvancedProperty

https://learn.microsoft.com/en-us/powershell/module/netadapter/get-netadapter

您还可以使用更全面的 WMI 类 MSFT_NetAdapter 创建自定义输出。 MSFT_NetAdapter 的描述如下:

https://msdn.microsoft.com/en-us/library/Hh968170(v=VS.85).aspx

这是一个命令,用于列出已启用(状态 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

Starting with Windows 8/Server 2012, you can try Get-NetAdapter and several more specialized commands like Get-NetAdapterAdvancedProperty:

https://learn.microsoft.com/en-us/powershell/module/netadapter/get-netadapter

You can also use the more comprehensive WMI class MSFT_NetAdapter to create customized output. MSFT_NetAdapter is described here:

https://msdn.microsoft.com/en-us/library/Hh968170(v=VS.85).aspx

Here's a command to list the speed and other properties of enabled (State 2), connected (OperationalStatusDownMediaDisconnected $false), 802.3 wired (NdisPhysicalMedium 14), non-virtual adapters on the local computer:

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
似梦非梦 2024-09-12 01:08:56

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

# return network speed as exit code

$speed = Get-WmiObject -Class Win32_NetworkAdapter | 
where { $_.speed -and $_.macaddress -and 
$_.name -notmatch 'wireless|wi-fi|bluetooth|802\.11' } | select -expand speed
exit $speed/1000000

My current version, taking out bluetooth and wireless cards (run with powershell -file script.ps1):

# return network speed as exit code

$speed = Get-WmiObject -Class Win32_NetworkAdapter | 
where { $_.speed -and $_.macaddress -and 
$_.name -notmatch 'wireless|wi-fi|bluetooth|802\.11' } | select -expand speed
exit $speed/1000000
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文