我试图在Windows 7上以编程方式设置物理接口的MTU:
PS> (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.Description -match '^Red Hat.*#2' }) DHCPEnabled : False IPAddress : {10.10.8.3, fe80::447d:38dc:bb39:f311} DefaultIPGateway : DNSDomain : ServiceName : netkvm Description : Red Hat VirtIO Ethernet Adapter #2 Index : 12 PS> (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.Description -match '^Red Hat.*#2' }).SetMTU(9000) Method invocation failed because [System.Management.ManagementObject#root\cimv2\Win32_NetworkAdapterConfiguration] doesn't contain a method named 'SetMTU'. At line:1 char:113 + (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.Description -match '^Red Hat.*#2' }).SetMTU <<<< (9000) + CategoryInfo : InvalidOperation: (SetMTU:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
即使这种方法存在,它仍然错误? 真的吗?
请帮忙。
PS> (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | \ Where { $_.Description -match '^Red Hat.*#2' }) | Get-Member
回报,其中包括:
MTU Property System.UInt32 MTU {get;set;}
但试图获得或设置它什么都不做:
(Get-WmiObject -Class Win32_NetworkAdapterConfiguration | \ Where { $_.Description -match '^Red Hat.*#2' }).MTU
除非有一个Invoke-Magic或者我需要做的事情。
根据Ryan的build议,我已经改变了IPv4 MTU(以及IPv6 MTU):
C:\>netsh interface ipv4 show subinterface "Local Area Connection 2" MTU MediaSenseState Bytes In Bytes Out Interface ------ --------------- --------- --------- ------------- 9000 1 3686 6624 Local Area Connection 2
看起来很好,但是只影响子接口 ,而不是硬件接口:

这甚至在重新启动之后。
好吧,这并不能真正回答你的问题,但是我猜这里面包含了一些体面的信息,所以我会留下来的。 希望有人有一个更好的。
做:
(Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.Description -match '^Red Hat.*#2' }) | Get-Member
并观察输出。 你会发现这个实例实际上并不包含一个名为SetMTU的方法,尽pipe这个文档说了什么。 编辑:其实你可能会。 但是我的networking接口没有这个function。 看起来像硬件特定的。
所以我知道我要做的是作弊,但它的作品:
PS C:\> $AdapterName = $(Get-NetAdapter | Where { $_.Name -Match 'Ethernet'}).Name PS C:\> netsh interface ipv4 set subinterface "$AdapterName" mtu=1500 store=persistent Ok.
所以就像你说的那样,为接口工作,但可能不适用于硬件网卡。 所以我没有真正回答你的问题。
你也在你的评论中提到了Set-NetAdapterAdvancedProperty 。 但是,我也没有在那里设置MTU。 Windows GUI中的设备属性也不能设置MTU。 我认为差异是硬件特定的。