In Guest VMware Tools CLI commands

In general it seems typical that VMware Tools gets installed on the Guest OS and then left alone after that. While doing some reading and working on some “slowness” issues, I’ve found the Tools CLI to become very handy and powerful.

On the Windows side of things here are a few “common” commands to use tools via the command line. First we need to get into the directory where tools is installed and the toolbox command can be run. The default directory is “C:\Program Files\VMware\VMware Tools”

The command below in the screenshot lists the base commands available with the VMwareToolboxCmd: VMwareToolboxCmd.exe help

vmwaretoolbox-help

I’m not covering all of the commands there but the documentation from VMware does a good job.

I’ve been using the VmwareToolboxCmd.exe stat “subcommandhere” for seeing stats within the GuestOS and I’ve included the snipit from the VMware doc with a little detail for each stat subcommand:

vmwaretoolbox-help-statsubcommands.PNG

As you can see it covers many useful areas to see if the VM is having performance issues related to CPU Limits perhaps or to see if any memory is ballooning, or swapping(I’ve also included memres and cpures just to see if your VM has any reservations):

vmwaretoolbox-stats

You can manually turn timesync with the host on/off/and check status:

vmwaretoolbox-timesync

Another command that I would imagine is useful would be the disk command and shrink subcommands that can be used to actually shrink and reduce the space the virtual disk takes up. As you can see from the screenshot my test VM is a linked clone and this can not be run against it. This doesn’t work against thick provisioned VMs as it wouldn’t shrink the virtual disk since the space has already been allocated for the virtual disk:

vmwaretoolbox-help-disk

**NOTE certain version of Fusion have a “Clean Up Virtual Machine” button and Workstation has a “Compact” menu command that will do the same thing.

The commands are pretty much the same within a Linux OS, below is a screenshot of a CentOS VM. The default directory for this is /usr/sbin/ and the command is “vmware-toolbox-cmd”:vmware-toolbox-cmd-help

There are many more commands that can be run from within the Guest OS, as I stated I’ve been using and seeing these commands used to track down slowness issues within VMs.

Note these commands were taken from the following User’s Guide from VMware and VMware vSphere 6.0 Documentation Center.

Advertisements

Memory Reservation Reporting & Changing Values via PowerCLI

I know there are many sources out there for setting values as far as limits are concerned (See Alan Renouf’s blog)with PowerCLI but I could not find anything about setting or removing reservations with commands found in PowerCLI.

I would like to thank Dean Grant (blog here) for the script to report on what VMs have either CPU or Memory reservations that do NOT equal 0. I have made a couple of slight changes as I was wanting to report VMs that only have Memory reservations and that did not match a specific name.

Here is the script for the reporting that will export to a CSV file(again this is mostly the script from Dean’s Blog with a few tweaks):

**Please note that -notlike could be changed to many different options such as -like or -eq. Also to select a specific # of VMs add the following after the closing } on the first line to select the first 5(or a number of your choosing) objects

| Select-object -First 5 

 $(
$VMs = Get-VM | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation -ne "0" -and $_.Name -notlike "InsertVMNameHere*"}

ForEach ($VM in $VMs)

{
"" | Select @{N="Name";E={$VM.Name}},
@{N="Memory Reservation";E={$VM.ExtensionData.ResourceConfig.MemoryAllocation.Reservation }}

}
) | Export-Csv C:\FILENAME.CSV

If you are wanting to change the reservations to a specific reservation value AND VM Share value you can use the below script which I had a bit of help from a VERY knowledgeable colleague VirtualServerGuy

**USE AT YOUR OWN RISK**

**Please note that -notlike could be changed to many different options such as -like or -eq. Also to select a specific # of VMs add the following after the closing } on the first line to select the first 5(or a number of your choosing) objects. Also note you need to replace the “#” for the MemReservationMB with a numerical value and you can alert the -MemSharesLevel to High/Low/Normal (or Custom but I have yet to test that) 

$VMs = Get-VM | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation -ne "0" -and $_.Name -notlike "InsertVMNameHere*"}

ForEach ($VM in $VMs){

Get-VM $VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -MemReservationMB "#" -MemSharesLevel Normal

}