I was asked by my friend Duncan if it was easy enough to set the Memory Management Unit (MMU) for each of his VM’s. Read his post here for more information on what he was working on.
He was about to set this by hand for 50+ VM’s which would take a while, so with the power of the VI Toolkit he can now take it easy whilst PowerShell does the hard work:
For one VM:
Get-VM -Name "MyVM" | Get-View | foreach {
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.flags = New-Object VMware.Vim.VirtualMachineFlagInfo
$spec.flags.VirtualMMuUsage = "on"
$taskMoRef = $_.ReconfigVM_Task($spec)
}
For all VMs you could use:
Get-VM | Get-View | foreach {
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.flags = New-Object VMware.Vim.VirtualMachineFlagInfo
$spec.flags.VirtualMMuUsage = "on"
$taskMoRef = $_.ReconfigVM_Task($spec)
}
Or for each of the VMs in a cluster:
Get-Cluster "MyCluster" | Get-VM | Get-View | foreach {
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.flags = New-Object VMware.Vim.VirtualMachineFlagInfo
$spec.flags.VirtualMMuUsage = "on"
$taskMoRef = $_.ReconfigVM_Task($spec)
}
To list each of the VM’s and their current MMU setting use this one-liner:
Get-VM | Get-View | ForEach {Write "$($_.Name) - $($_.Config.Flags.VirtualMmuUsage)"}