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:
That's even after a reboot.