Category Archives: powershell

PS: Get cluster CPU/Memory over-subscription

I am not the originator of these code (sorry I don’t remember where in google land they came from), but am posting it here for reference, since I may need to reuse it someday.

Note: CPU calculation is divided by 2 due to hyper-threading

#get cluster CPU over-subscription
Get-Cluster | Sort name | Select Name, @{N="CpuOversubscriptionFactor";E={[math]::Round((($_|get-VM|measure numcpu -sum).Sum)/(($_|get-vmhost|measure numcpu -sum).sum)/2,2)}}

#get cluster Memory over-subscription
Get-Cluster | Sort name | Select Name, @{N="MemOversubscriptionFactor";E={[math]::Round((($_|get-VM|measure MemoryGB-sum).Sum)/(($_|get-vmhost|measure MemoryTotalGB -sum).sum),2)}}

#get VMHost CPU over-subscription in a cluster
Get-Cluster <name> | Get-VMHost | Sort name | Select Name, @{N="CpuOversubscriptionFactor";E={[math]::Round((($_|get-VM|measure numcpu -sum).Sum)/(($_|measure numcpu -sum).sum)/2,2)}}
Leave a comment

Posted by on May 30, 2020 in powershell



This set of scripts were developed using similar concept as vchecks but for a more real world enterprise usage. Its not that vcheck is not good, but when you are in a big company, having to read a vcheck email to check the status of daily is very tired. vChecks suffers from the following:

  • Lack of over RAG (red/amber/green) status on subject line. I agree that its hard to really determine what should be red or amber. But in an enterprise operations, RAG give a quick overview of your status. So if the subject says green, you really don’t need to read through the email. Having said that, this script doesn’t send any emails, more about this later.
  • You don’t know if a plugin was successfully executed or not. When a vcheck plugin executes, it either produces a select object or doesn’t. Not producing a select object could also mean that script did not execute. For enterprise operations, its essential to know if each health is executed and the status even if its all green.
  • If I need to run vchecks continuously, say every 30 mins or hour, it may not be achievable because in an enterprise setting, it may take a while to complete a full run of vchecks.

This is an alternate version of vCheck-like script written by me, but sending status outputs to a log file instead. This was developed as the use case for vCheck did not fit with a large enterprise operation organisation.

Git hub repo here ->

Leave a comment

Posted by on April 19, 2020 in powershell, Scripts, vmware


PowerCLI: Up time of virtual machines

2 very prominent solutions are offered when you try to search for powerCLI scripts to check up time of virtual machines in your estate

  • $vm.ExtensionData.Runtime.BootTime
  • Get-Stat -Entity $VM -State sys.uptime.latest -RealTime -MaxSample 1

I don’t even know why some people recommends them. It is very obvious from other posts that these values have issues.

$vm.ExtensionData.Runtime.BootTime is not a consistent value, i.e. the value is not there all the time.

whereas, sys.uptime.latest only records the uptime in that host. If the VM is moved to another host, this is reset

It also took me awhile to find the correct solutions and it was quite frustrating because many techies just blindly offer the wrong advise to users.

Anyway, the correct method is this:

Get-Stat -Entity $VM -State sys.osuptime.latest -RealTime -MaxSample 1

You can compare the values on the same VM, yourself

Leave a comment

Posted by on March 22, 2020 in powershell, vmware


vSphere: Enable/Disable DRS Host rules with PowerCLI

I know that the latest version of PowerCLI already have commandlet to will enable/disable DRS host rules. But when you are in operations, you don’t really get to use the latest version of PowerCLI all the time. Anyway, this is just a placeholder for myself, but if you find it useful great for you.

Disclaimer: This is not my original work, I forgot where I ripped the codes from, but its not my original work. Apologize for the bad formatting.

#Filename = Set-DRSVMHostRules.ps1

$cluster = Get-Cluster 
$ClusName $rule = $cluster | 
  Get-DrsRule -Type VMHostAffinity -Name $RuleName 
$spec = New-Object VMware.Vim.ClusterConfigSpec
$ruleSpec = New-Object VMware.Vim.ClusterRuleSpec 
$ruleSpec.Info = $rule.ExtensionData 
$ruleSpec.Info.Enabled = $Enable 
$ruleSpec.Operation = "edit" 
$spec.rulesSpec += $ruleSpec 

$cluster.ExtensionData.ReconfigureCluster($spec,$true) | Out-Null
$cluster | Get-DrsRule -Type VMHostAffinity -Name $RuleName

get-cluster ClusterABCDC | Get-DrsRule -Type VMHostAffinity | 
% { .\Set-DRSVMHostRules.ps1 -ClusName $_.cluster -RuleName $ -Enable $true}
Leave a comment

Posted by on July 21, 2019 in powershell, vmware


Tags: , ,

vSphere: A colorful DCUI welcome screen

I was tasked to make our ESXi hosts compliant to the security standards and one of them is to set the legal message on DCUI. The work is easy enough, however you end up with only a black screen with the legal text and it looks very ugly!

So I chanced upon two links which shows you how you can add colors and format to the welcome message. Unfortunately, none of them shows you how to get it right.

Read the rest of this entry »
Leave a comment

Posted by on March 15, 2019 in powershell, Scripts, vmware


Tags: ,

Using REST API calls on VCE Vision

In VCE Vision, you can use REST API calls to grab the status of the overall system, drill down to the individual components and, when required e.g. for support calls, grab the full vblock information into an XML.

Conventionally, you would use a browser using the URL https://vision_core:8443/fm/systems to login and get the overall system’s health in an XML format. To grab the entire XML data you call https://vision_core:8443/fm/{dbid}/allblockdata. Over time, I find that grabbing allblockdata or drilling down to individual components can provide some insight to why a component is showing RED (for example, due connectivity error). Instead of logging in all the time, why not make REST API calls and grab the data instead?

Read the rest of this entry »
Leave a comment

Posted by on January 5, 2019 in powershell, Scripts


PS: How to get ESXi multipath storage with Powerpath

If your vSphere’s ESXi hosts are connected to storage via EMC’s powerpath, the convention methods of querying path info will not work. Basically, you will get zero results.

For example when you query the lun via MultipathInfo you may only see iSCSI luns listed (if you have them running), but not your datastores. Read the rest of this entry »

Leave a comment

Posted by on August 21, 2018 in powershell, vmware