Powercli oneliner for changing MTU to 9000

I wanted to set MTU on number of standard vSwitches across multiple ESXi hosts and Powercli made that job easier. Here’s a oneliner to get the job done across multiple vSwitches.

Get-VMHost My-ESXi-Host| Get-VirtualPortGroup "PG_SearchString*" | Get-VirtualSwitch | Set-VirtualSwitch -Mtu 9000 -Confirm:$false




Find aggregate allocated VM CPU and Memory per host basis

Here’s a quick and dirty one-liner to find the total allocated CPU & Memory per ESXi host basis. This is useful when you want to get a quickly get your over-commitment ratios.

$TotalMem=0; Get-VMHost myESXiHost1 | Get-VM | ?{$_.PowerState -match 'PoweredOn'} | %{$TotalMem=$TotalMem+$_.MemoryGB};Write-Host $TotalMem
$TotalCPU=0; Get-VMHost myESXiHost2 | Get-VM | ?{$_.PowerState -match 'PoweredOn'} | %{$TotalCPU = $TotalCPU+$_.numCPU};Write-Host $TotalCPU

Enumerating GuestId supported by VMware ESXi

Today when googling for various GuestId supported by VMware ESXi, I found a cool way that someone posted to “serverfault”. Here is a piece of PowerCLI code to do exactly that:


For reference, here is the original link where I found this:



LUN Runtime Name


Most vSphere Administrators need to inspect the LUN runtime names discovered by the ESXi hosts. What usually gets overlooked is that runtimes name across different hosts could be different. Hence I like to look at all the runtime names discovered across all hosts for that ‘said’ LUN. Here is an oneliner which does the same, pass the CanonicalName (NaaID) and it will tell you the RuntimeName:

function Get-DatastoreRuntimeName() {
    param (
        [string]$CanonicalName = $(Read-Host -prompt "Enter a CanonicalName")

    Get-VMHost `
        | Get-VMHostStorage `
        | Select-Object -ExpandProperty ScsiLun `
        | ?{$_.LunType -like "disk"} `
        | Select-Object VMHost,CanonicalName,RuntimeName,@{Name="CapacityGB";Expression={[int]$_.CapacityGB}} `
        | ?{$_.CanonicalName -like $CanonicalName}

What I usually do is find the NaaID for a Datastore and then use the NaaID to query the RuntimeName. Yes that’s a 2 step process. There might be an better way, but haven’t tried to explore it, since this gets my job done. 😉

vSphere Datastore Report

I needed to generate a Datastore report. All the information I was interested in was available in via the Get-Datastore cmdlet, however it was nested deep. Hence churned up a quicky PowerCLI oneliner:

Get-Datastore `
    | Select-Object -ExpandProperty ExtensionData `
    | Select-Object `
        @{Name="Name"; Expression={$_.Name}},`
        @{Name="CanonicalName"; Expression={$_.Info.Vmfs.Extent.DiskName}},`
        @{Name="CapacityGB"; Expression={[int]($_.Summary.Capacity/1GB)}},`
        @{Name="FreeGB"; Expression={[int]($_.Summary.FreeSpace/1GB)}},`
        @{Name="ProvisionedGB";Expression={[int](($_.Summary.Capacity - $_.Summary.FreeSpace + $_.Summary.Uncommitted)/1GB)}},`
        @{Name="Moref"; Expression={$_.MoRef}} `
    | ft

In case you are interested in the details of a specific datastore, you can filter the output from the previous oneliner, using the Where-Object cmdlet.

Check VMHost VAAI Status

I needed a quick way to generate a report about VAAI status for all hosts in the vCenter Server. Hence wrote a PowerCLI oneliner to get the job done:

Get-VMHost  | %{ 
  Get-AdvancedSetting -Name DataMover.HardwareAcceleratedMove -Entity $_
  Get-AdvancedSetting -Name DataMover.HardwareAcceleratedInit -Entity $_
  Get-AdvancedSetting -Name VMFS3.HardwareAcceleratedLocking  -Entity $_
} | Select-Object `
        @{Name="Name"; Expression={$_.Entity}},`
        @{Name="PropertyName"; Expression={$_.Name}},`
        @{Name="Status"; Expression={ if($_.Value){"Enabled"} else{"Disabled"}}}

In case you are not aware of what VAAI is read about it here at KB#1021976.