Author Archives: chouse

Change root password on all vSphere ESXi hosts

Adapted from Change root password on all (or some) vSphere h… | VMware Communities.

$vCenter = "vcenterserver"
$oldpw = "oldpwd"
$newpw = "newpwd"

connect-viserver -server $vCenter -Credential (Get-Credential)
$hosts = @() 
write-host "Querying for ESXi hosts..."

Get-VMHost | sort | Where {$_.ConnectionState -eq "Connected" -or $_.ConnectionState -eq "Maintenance"} | Get-View | Where {$_.Summary.Config.Product.Name -match "i"} | % { $hosts+= $_.Name }

Disconnect-VIServer -confirm:$false

foreach ($vmhost in $hosts) {
    write-host "Connecting to $vmhost..."
    connect-viserver -server $vmhost -user root -password "$oldpw"
    write-host "Changing root password on $vmhost..."
    Set-VMHostAccount -UserAccount root -password "$newpw"
    Disconnect-VIServer -confirm:$false
}

Cpu.PcpuMigrateIdlePcpus

Don’t forget to set the advanced ESXi setting “Cpu.PcpuMigrateIdlePcpus” back to its default value of 4 if it was changed to 0 as a workaround for the issue described in http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2033780.

In over-committed CPU environments (VDI), having Cpu.PcpuMigrateIdlePcpus disabled can increase CPU Ready time. It should be set back to its default of 4 as the official patch for the issue (http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2051208) states.

Here is a 6-month graph for a single host (CPU | Ready) showing the 5-month period where Cpu.PcpuMigrateIdlePcpus was disabled in mid-February and re-enabled (back to default) a few days ago:

period of high cpu ready

The setting can be changed quickly and easily across all hosts via PowerCLI: Set advanced settings on all hosts.

Count of powered-on VMs by host or datastore

Via One Liner: How many VMs ? | Virtu-Al.Net.

If you have an environment with a lot of powered-off VMs, you may only want a count of powered-on VMs per host, instead of a count of the total number of VMs per host:

Get-VMHost | Select @{N="Cluster";E={Get-Cluster -VMHost $_}}, Name, @{N="NumVM";E={($_ | Get-VM | where {$_.powerstate -eq "poweredon"}).Count}} | Sort Cluster, Name

To get a count of powered-on VMs for a datastore:

get-datastore linked_clones | Get-VM | where {$_.powerstate -eq "poweredon"} | measure-object

Set advanced settings on all hosts

Got an advanced setting to change on all hosts? PowerCLI to the rescue:

Get-AdvancedSetting -entity (get-cluster ClusterName | get-vmhost) -name "Advanced.Option" | set-advancedsetting -value 'VALUE_HERE' -confirm:$false

Speed up entering maintenance mode

… via PowerCLI by moving all the powered-off VMs to some other host while DRS handles the powered-on ones:

get-vmhost <maint mode host> | get-vm | where {$_.powerstate -eq "poweredoff"} | move-vm -destination <other host>