簡體   English   中英

PowerShell腳本,以獲得Windows計算機的網卡速度

[英]PowerShell script to get network card speed of a Windows Computer

什么是PowerShell腳本以獲得特定Windows機器的網卡運行速度?

我知道這可以通過基於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參數采用數組,因此您可以針對多台計算機運行此操作,前提是您擁有權限。 用*****替換Format-Table屬性列表以獲得更全面的可用屬性列表。 您可能希望過濾這些屬性以刪除您不感興趣的條目。

使用內置字節乘數后綴(MB,GB等)也可以根據您的需要使速度更具可讀性。 您可以將此指定為Format-Table -Property數組上的HashTable條目,例如

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

從Windows 8 / Server 2012開始,您可以嘗試使用Get-NetAdapter和其他幾個專門的命令,如Get-NetAdapterAdvancedProperty

https://docs.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

我目前的版本,取出藍牙和無線卡(與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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM