Skip to main content

I got asked to change all the MTU to all Host on a particular environment in order to standardize this setting and avoid any possible drifts or issue.


In the end is pretty simple if you environment is already quite similar, in my case all the vmotion interfaces are on VMK1 so I found really useful this command:

Get-VMHost | Get-VMHostNetworkAdapter -name "vmk1" | Foreach { $_ | Set-VMHostNetworkAdapter -Mtu 1600 -Confirm:$false }

or

Get-VMHost | Get-VMHostNetworkAdapter -name "vmk1" | % { $_ | Set-VMHostNetworkAdapter -Mtu 1600 -Confirm:$false }

Of Course before launching it, test it on a test environment connecting to your vcenter using the basic command:

Connect-ViServer "vCenter-FQDN or IP"

EXPORT VMkernels Info for All Hosts

So you can simply change the MTU of a specific VMkernel Interface to all of your host and in case you want to double check your environment and having this info on a CSV file you can use this:

$vHosts = Get-VMHost | Sort-Object Name

Begin first loop

foreach ($vHost in $vHosts) {
$VMHost = $vHost.Name
$vmks = $vHost | Get-VMHostNetwork | Select-Object -ExpandProperty VirtualNic | Sort-Object Name

#Begin second / nested loop
foreach ($vmk in $vmks) {
    $VmkObjct = [pscustomobject] @{'VMHost' = $vmk.VMHost
                                   'DeviceName' = $vmk.DeviceName
                                   'IP' = $vmk.IP
                                   'DhcpEnabled' = $vmk.DhcpEnabled
                                   'SubnetMask' = $vmk.SubnetMask
                                   'Mac' = $vmk.Mac
                                   'VMotionEnabled' = $vmk.VMotionEnabled
                                   'ManagementTrafficEnabled' = $vmk.ManagementTrafficEnabled
                                   'MTU' = $vmk.Mtu}

$VmkObjct | Export-Csv -Path C:\vmkernels.csv -Append -NoTypeInformation   
Write-Output $VmkObjct
}#Closing curly bracket for second / nested loop

}#Closing curly bracket for first loop

IF you care interested there’s also another interesting blog regarding this:
https://www.virtu-al.net/2013/05/24/altering-vmkernel-nic-mtu-with-powercli/

I hope you will find this useful

Leave a Reply

Giovanni Dominoni's Tech Blog