A. Mikkelsen

VMware ESX scripts, commands, tools and other nice to know things that will make your virtualization days easier!!!!

Yesterday we released version 49 of the ESXHealthScript.

Kenneth Mazie. (kcmazie aka. kcmjr) has done a huge job in updating and adding new features to the script.

  • Added automatic detection for ESX 3 or ESX 4
  • Added corrections for changes with ESX4
  • Added Cisco CDP info listing (from user Carson)
  • Added corrections to v4 tomcat server

To read more about the ESXHealthScript please visit the project web site.

If you are using the script, and have ideas for new features/functions, please let us know on the projects website or even better post the needed code ūüôā

vLogView by Xtravirt

No comments

vLogView, helps you view and search all LOG files from each of your ESX hosts from a single application.

For more info and the latest download, visit http://xtravirt.com/xd10132


Playing with PowerCLI


Last week I attended a Magirus course on administrating you VMware environment using PowerCLI, and below is some of the small scripts I created.

These code sniplets will help you manage your VMware environment and give you some ideas of how powerful the VMware PowerCLI really is.

I’m sure VMware will add even more CMDLETS to the PowerCLI in the feature.

Get the latest PowerCLI here.
A function to load different PSSnapins.
Put it in the beginning of all you Powershell scripts,
to load the different PSSnapin you need.

function LoadSnapin{
  if (!(Get-PSSnapin | where {$_.Name   -eq $PSSnapinName})){
    Add-pssnapin -name $PSSnapinName
LoadSnapin -PSSnapinName   "VMware.VimAutomation.Core"

Clone a VM to template.

$VMToClone = "vm_name"
$TemplateName = "TemplateName"
$Datacenter = "Training"
get-vm $VMToClone| stop-vm
New-Template -VM $VMToClone -Name $TemplateName 
   -Location $(Get-Datacenter $Datacenter)

Convert Template to VM – without changing the name.

$TemplateName = "TemplateName"
Set-Template -Template $(get-template $TemplateName) -ToVM

Convert VM to Template – without changing the name.

$VMtoTemplate = "vm_name"
$vm = Get-VM $VMtoTemplate | Get-View

Deploying a VM from template.

$strNewVMName = "NewVM_01"
$strTemplate = "TemplateName"
$strDestinationHost = "ESX01"
New-VM -Name $strNewVMName -Template $(get-template   $strTemplate) 
   -VMHost $(Get-VMHost $strDestinationHost)

Deploying a VM from template using a Customization Specification and using Thin provisioning.
Make sure the CustomSpec has been created beforehand.

$strNewVMName = "NewVM_01"
$strTemplate = "TemplateName"
$strDestinationHost = "ESX01"
$strCustomSpec = "TEST-CustomSpec"
New-VM -Name $strNewVMName -Template $(get-template $strTemplate) 
   -VMHost $(Get-VMHost $strDestinationHost) -DiskStorageFormat 
   Thin -OSCustomizationSpec $(Get-OSCustomizationSpec $strCustomSpec)

Moving a VM to a specific folder.

$strDistinationFolder = "MyFolder"
$strDatacenter = "Training"
$VMToMove = "MyVM"
move-vm -VM $(get-vm $VMToMove) -Destination $(Get-Folder 
    -Name $strDistinationFolder -Location $(Get-Datacenter $strDatacenter))

Copying a file to a Windows VM (With or without network access)
Requires VMware tools to be running.

$VM = get-vm -name "myVM"
$target = "C:\MY_DIR\"
$source = "C:\MY_DIR\test.txt"
Copy-VMGuestFile -Source $source -Destination $target -vm $VM 
   -LocalToGuest -HostUser "root" -HostPassword "password" 
   -GuestUser "myVM\administrator" -GuestPassword "password" 

Copying a file from a Windows VM (With or without network access)
Requires VMware tools to be running.

$VM = get-vm -name "myVM"
$target = "C:\MY_DIR\"
$source = "C:\MY_DIR\test.txt"
Copy-VMGuestFile -Source $source -Destination $target -vm $VM 
   -GuestToLocal -HostUser "root" -HostPassword "password" 
   -GuestUser "myVM\administrator" -GuestPassword "password" 

Listing the content of “C:\Windows\System32” from a VM – remotely

$VM = get-vm -name "myVM"
Invoke-VMScript -VM $VM -ScriptText "dir" -HostUser "root" 
   -HostPassword "password" -GuestUser "myVM\administrator" 
   -GuestPassword "password"

Run msinfo32 on a guest VM and pipe the output to a TXT file – Using PowerShell.

$VM = get-vm -name "myVM"
$script = '&"$env:ProgramFiles\Common Files\Microsoft Shared\
   MSInfo\msinfo32.exe" /report "$env:Tmp\inforeport.txt"'
Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" 
   -HostPassword "password" -GuestUser "myVM\administrator" 
   -GuestPassword "password"

Open the above output file in the guest VM – Using PowerShell.

$VM = get-vm -name "myVM"
$script = '&"notepad.exe" "$env:Tmp\inforeport.txt"'
Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" 
   -HostPassword "password" -GuestUser "myVM\administrator" 
   -GuestPassword "password" -ScriptType Powershell

Run msinfo32 on a guest VM and pipe the output to a TXT file – Using batch commands.

$VM = get-vm -name "myVM"
$script = '&"%programfiles%\Common Files\Microsoft Shared\
   MSInfo\msinfo32.exe" /report "%tmp%\inforeport.txt"'
Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" 
   -HostPassword "password" -GuestUser "myVM\administrator" 
   -GuestPassword "password" -ScriptType Bat

Open the above output file in the guest VM – Using batch commands.

$VM = get-vm -name "myVM"
$script = '"notepad.exe"   "%Tmp%\inforeport.txt"'
Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" 
   -HostPassword "password" -GuestUser "myVM\administrator" 
   -GuestPassword "password" -ScriptType Bat

If you need a good guide to Interpreting the statistic from ESXTOP then take a look at this guide from VMware.


I’m using it to troubleshoot performance issues (poor response times) from clients in different locations, when using the remote console.

Restarting the Management agents on ESX Server 3.x

  1. Login to the ESX host using SSH (or from COS)
  2. Type service mgmt-vmware restart.
    Before restarting the Management Agent make sure that Automatic Startup/Shutdown is Disabled
    For more info see
    Restarting hostd (mgmt-vmware) on ESX Server Hosts Restarts Hosted Virtual Machines Where Virtual Machine Startup/Shutdown is Enabled (1003312)
  3. Type service vmware-vpxa restart.
  4. Exit the SSH session or logout of COS

Below solution is on you own risk.

  1. Download the Bios/Embedded Controller from IBM/Lenovo (Diskette version)
  2. Rename the file UPDTFLSH.EXE to UPDTFLSH.EXE.OLD
  3. Create a copy of QKFLASH:EXE and rename it to UPDTFLSH.EXE
  4. Boot the labtop from the diskette
  5. Follow normal procedure for updating BIOS/Embedded Controller
  7. When the BIOS/Embedded Controller is updated the PC will trun off
  8. Poweron  and enter BIOS (F1) to verify that the new BIOS/Embedded Controller is installed.

Just found this very interesting article http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1013109 describing a problem with Windows 2008 and ESX 4 virtual hardware version 7.

In short the article states that you might have the disks go offline in a Windows 2008 VM if you

  • Upgrade virtual hardware from version 4 to 7
  • Installing a new VM with virtual hardware 7

There is two ways to get around this (taken from the VMware KB 103109)


This can be resolved by changing the SAN Automount Policy on the system. See the Microsoft article http://support.microsoft.com/kb/973834 to change the SAN Policy to online.
The SAN policy is defined within the VDS environment of the system and is represented by the following values:
  • VDS_SP_UNKNOWN = 0x0
  • VDS_SP_ONLINE = 0x1
  • VDS_SP_OFFLINE = 0x3
On Windows Server 2008 Enterprise and Windows Server 2008 Datacenter, the default SAN policy is VDS_SP_OFFLINE_SHARED. On all other Windows Server 2008 editions, the default SAN policy is VDS_SP_ONLINE.
To query current SAN policy from the command line, start DISKPART and issue a SAN command:
SAN Policy : Offline Shared


Alternatively, you can set the disk to Online after the hardware version upgrade.
To set the disk to Online:
  1. Log in to your system as an Administrator.
  2. Click Computer Management > Storage > Disk Management.
  3. Right-click the disk and choose Online.

Free virtualization fools

1 comment

David Davis has put together a list of what he thinks is some of the best free virtualization tools avaiable.

I still think that he is missing a few, like

See the full article at

Project Onyx Alpha Release

No comments

Finally everyone outside the closed beta is now able to get hands on with the cool application Project Onyx.
Thanks to Carter Shanklin

Project overviewGot it from http://www.ntpro.nl/blog/archives/1330-Project-Onyx-Alpha-Release.html

Onyx is a standalone application that serves as a proxy between the vSphere Client and the vCenter Server. It monitors the network communication between them and translates it into an executable PowerShell code. Later, this code can be modified and saved into a reusable function or script.

  1. To connect to a server, click the “Connect” icon.
  2. Enter the IP of the vCenter Server on which you want to work and click Connect.
  3. Connect with any of the following clients:For vSphere Client, in the “IP Address” field enter the following address:
    http:// [IP of the machine where Onyx is running] : [listening port]

    For vSphere PowerCLI, run the following command:
    Connect-VIServer [IP of the machine where Onyx is running] -Protocol http
    -Port [listening port] -User [username] -Pass [password]

  4. To start the generation of PowerCLI.NET scripts, click the “Start” icon.
  5. To save the generated script, click the “Save output to file” icon.

You can download Project Onyx Alpha from http://blogs.vmware.com/files/onyx_1.5.3607.25516.zip or http://bit.ly/vmwOnyx15.

To learn how it works please see this video from YouTube.com

If you are looking for a easy and simple guide for setting up iSCSI on vSphere (ESX 4.x) you might want to take a look at this guide from www.techhead.co.uk