Altering VMKernel NIC MTU with PowerCLI

I was asked if it was possible to set the VMKernel Nic MTU in PowerCLI, after looking on the internet there were several people showing how to do this but some of them were very complicated, maybe this has got easier over time as with each release of PowerCLI one of the things the PowerCLI Dev team looks at is how to make things easier for the end user?

Anyway, I thought I would show my one line solutions for listing and setting the MTU for the VMKernel Nics for multiple hosts,

Listing the MTU for each VMKernel Nic

image

Setting the MTU to 9000 for each VMKernel Nic

image

The Code

Listing the MTU for each VMKernel Nic

Get-VMHost | Get-VMHostNetworkAdapter | Where { $_.GetType().Name -eq "HostVMKernelVirtualNicImpl" } | Select VMHost, Name, MTU

Or an even easier way of doing this (but you cant expand it to change the MTU easily is:

Get-VMHost | Get-VMHostNetwork | Select -ExpandProperty VirtualNic | Select VMHost, Name, MTU

Setting the MTU to 9000 for each VMKernel Nic

Get-VMHost | Get-VMHostNetworkAdapter | Where { $_.GetType().Name -eq "HostVMKernelVirtualNicImpl" } | Foreach { $_ | Set-VMHostNetworkAdapter -Mtu 9000 -Confirm:$false }

7 thoughts on “Altering VMKernel NIC MTU with PowerCLI

  1. Pingback: Change MTU on Host VmKernel Interface - GiovanniDominoni.it

  2. Pingback: VMware vSphere 6.5 Change vmkernel MTU size - Virtualization Howto

  3. Robin

    Ah, I needed to use “Get-VMHostNetworkAdapter -Name ‘vmk1′” rather than “Get-VMHostNetworkAdapter -PortGroup ‘iscsi-a’”

  4. Robin

    When connected directly to an ESXi 6.0 host, using the latest PowerCLI, and running: “Get-VMHostNetworkAdapter -PortGroup ‘iscsi-a’ | Set-VMHostNetworkAdapter -Mtu 9000 -Confirm:$false” I get “Set-VMHostNetworkAdapter The object has already been deleted or has not been completely created” and a ManagedObjectNotFound exception. This is the same regardless of whether I prefix with Get-VMHost.

  5. keksbert

    Meantime you can do this on vSphere 5.5 like this:

    ## Set all VMKernel NICs to a MTU size
    Get-VMHostNetworkAdapter -VMKernel | Set-VMHostNetworkAdapter -Mtu 9000

    ## Set MTU for specific portgroup or vmkernel
    Get-VMHostNetworkAdapter | where { $_.PortGroupName -eq $VMKERNEL } | Set-VMHostNetworkAdapter -Mtu 9000 -Confirm $false

    ## Set mtu for specific vmk interface
    Set-VMHostNetworkAdapter -VirtualNic vmk3 -Confirm -Mtu 9000

  6. Robert van den Nieuwendijk

    I think the last example could be done without the ForEach:
    Get-VMHost | Get-VMHostNetworkAdapter | Where { $_.GetType().Name -eq “HostVMKernelVirtualNicImpl” } | Set-VMHostNetworkAdapter -Mtu 9000 -Confirm:$false

  7. Pingback: Обзор блогов от 27/05/13 | vMind.ru

Leave a Reply to Robin

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.