5

I'm trying to set the MTU for a physical interface programmatically on Windows 7:

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

Even though this method exists it still errors? Seriously?

Please help.


PS> (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | \
    Where { $_.Description -match '^Red Hat.*#2' }) | Get-Member

returns, among other things:

MTU                          Property     System.UInt32 MTU {get;set;}

But trying to get or set it does nothing:

(Get-WmiObject -Class Win32_NetworkAdapterConfiguration | \
    Where { $_.Description -match '^Red Hat.*#2' }).MTU

Unless there's an Invoke-Magic or something I need to do.


As per Ryan's suggestion I had already changed the IPv4 MTU (and IPv6 MTU for good measure):

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

Seems well and good, but that only affects the subinterface, not the hardware interface:

hw interface mtu = 1500

That's even after a reboot.

2

Alright, this doesn't really answer your question, but I guess it contains some decent information anyway, so I'll leave it up. Hopefully someone has a better one.

Do:

(Get-WmiObject -Class Win32_NetworkAdapterConfiguration | 
Where { $_.Description -match '^Red Hat.*#2' }) | 
Get-Member

And observe the output. You will see that this instance does not actually contain a method named SetMTU, despite what that documentation says. Edit: Actually yours might. But my network interface does not have that. Looks like it's hardware-specific.

So I know what I'm about to do is cheating, but it works:

PS C:\> $AdapterName = $(Get-NetAdapter | Where { $_.Name -Match 'Ethernet'}).Name
PS C:\> netsh interface ipv4 set subinterface "$AdapterName" mtu=1500 store=persistent
Ok.

So like you said, that works for the interface, but maybe not for the hardware NIC. So I haven't truly answered your question.

You also mentioned Set-NetAdapterAdvancedProperty in your comments as well. However, I do not have an MTU setting there, either. Nor can I set the MTU on the device properties in the Windows GUI. I think the differences are hardware-specific.

  • I already did something very similar (the netsh command on 'Local Area Connection 2') and it only changed the interface MTU but not the physical interface :(. I'll try again. – MikeyB Dec 9 '14 at 13:33
  • Added more details. Perhaps that works on Windows 8, but not 7. :/ – MikeyB Dec 9 '14 at 17:01
  • @MikeyB You are very correct in that the netsh command that I supplied applies to the interface and not directly to the hardware. The bad news is that interfacing with the hardware is something that would have to be exposed by the device driver. It'll be manufacturer and driver specific for your card. For instance, I do not have the same options in my drop down menu as you have in your screenshot. – Ryan Ries Dec 9 '14 at 17:15
  • Set-NetAdapterAdvancedProperty… OH WAIT! twitter.com/Supermathie/status/542075228860731394 Yeah that's right. Windows. Anything you want is only in the next version. – MikeyB Dec 9 '14 at 18:53
  • i.e.: Set-NetAdapterAdvancedProperty in theory does exactly what I want but isn't available until Windows 8. Also: despite having a MTU property, SetMTU doesn't exist on my system either. :( – MikeyB Dec 9 '14 at 19:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.