List all vm’s and total assigned diskspace

Looking for new scripts i’ve stumbled opon the following script to list all vm’s to an excel sheet and display the total assigned diskspace:

# Define Variables 
$outputFile = 'C:\VMDiskCapacity.csv' 
$VCServer = "vcenter.mydomain.com" 
$username = "vcenter_admin" 
$pass = "password" 

################## 
# Add VI-toolkit # 
################## 
Add-PSsnapin VMware.VimAutomation.Core 
Initialize-VIToolkitEnvironment.ps1 

# Connect server 
$VC = Connect-VIServer -Server "$VCServer" -User "$username" -Password "$pass" 

$myCol = @()    # Prepare output collection 
$VMs = Get-VM | sort Name    # Get all VMs (sorted) 
$counter = 0    # Initialize counter for progress bar 
ForEach ($VM in $VMs)    # Loop through VMs 
   { 
   $counter++    # Increase counter for progress bar 
   Write-Progress -Activity "Gathering disk information" -Status "Processing VM $VM" -PercentComplete (100*($counter/$VMs.count))    # Display progress bar 
    
   $myObj = "" | 
   select VM, TotalDiskSizeGB # Create output object 
   $myObj.VM = $VM.Name    # Virtual Machine Name 
    
   $TotalDiskSizeKB = 0 
   ForEach ($DISK in $VM.HardDisks)    # Loop through VM's harddisks 
      { 
      $TotalDiskSizeKB += $DISK.CapacityKB    
      } 
    
   $myObj.TotalDiskSizeGB = [math]::Round(($TotalDiskSizeKB * 1KB / 1GB),0) #Disk Size in GB 
   $myCol += $myObj    # Add output to collection 
   } 
$myCol | Export-Csv $outputFile -NoTypeInformation  # Export output to csv 

VMotion error CPUID mismatch on same hardware

We recently acquired a new Dell PowerEdge for our VMware Cluster. Although the hardware was the same, we did get a vmotion error like this one:

vmotion error

After investigating the problem, it looked like the virtual center server added maskid’s on it own to the virtual machines. After deleting this masks vmotion could occur without any problem. You can see themas settings in the following picture:

CPUID

To remove the mask id, do the following:

  • Shut down the virtual machine
  • Edit the settings of the virtual machine
  • Go to the options tab
  • Click the CPUID Maks setting
  • Click the Advanced Button
  • Press Reset all to default
  • Power on the virtual machine

After doing this, you should have no settings in this advanced page.

This happened on ESX 3.5 u2, an alternative for this solution is to upgrade to ESX 3.5 u4 and use EVC.

ESXi 4 on a bootable USB key

  1. Download ESXi 4.o VMware-VMvisor-Installer-4.0.0-164009.x86_64.iso
  2. Open image.tgz
  3. Open image.tgz\usr\lib\vmware\installer\VMware-VMvisor-big-164009-x86_64.dd.bz2
  4. Extract VMware-VMvisor-big-164009-x86_64.dd to your local hardrive
  5. Attach the USB flash drive and make sure you no longer need the data on it
  6. Use WinImage to transfer VMware-VMvisor-big-164009-x86_64.dd to the USB flash drive
    1. Disk->Restore Virtual Hard Disk image on physical drive…
    2. Select the USB flash drive (Warning: If you select the wrong disk you will lose data!)
    3. Select the image file VMware-VMvisor-big-164009-x86_64.dd
    4. Confirm the warning message
    5. Wait for the transfer to complete
  7. Unplug the USB flash drive (Warning: If you forget to unplug the flash drive from the PC you might lose the data on your hard drives the next time you boot!)
  8. Attach the USB flash drive to the machine you want to boot (Warning: If ESX Server 4i recognizes local drives, you might lose the data on it, so make sure you don´t need it anymore or unplug all hard drives!)
  9. Turn the machine on and make sure the USB flash drive is selected as boot device
  10. Watch ESX Server 4i boot
  11. Configure
  12. Enjoy!

Running PowerShel Scripts to generate ESX Reports

In my previous post i have written about a script that gave an output of the datastore usage of your esx hosts. For this you need to run a powershell script against your virtual center server.

Before you can run this script you have a few requirement, this requirements are:

After installing the Microsoft PowerShell and VI Toolkit for Windows you have to place your scripts in the script directory (c:\program files\vmware\infrastructure\vitoolkitforwindows\scripts)

Check your rights, it should be unrestricted: “powershell get-executionpolicy”.
If your result is: “Restricted”, type in the following command: “powershell set-executionpolicy unrestricted”

Now you can run your scripts by starting the “VMware VI Toolkit (for windows)”, this option can be found under start > programs > vmware > vmware vi toolkit

VMware ESX Datastore Reports – PowerShell

Using Microsft PowerShell and the VI Toolkit for Windos you can do some nice stuff. When looking for a way to make reports for a customer of my i’ve stumbled upon a few scripts.

All you have to do is to install Microsoft Powershell, VI toolkit for windows and have Office on your machine. When running the powershell script [wpdm_file id=”4″] i get the following output:

Datastore Chart

Contents of datastore.ps1:

if ((Test-Path  REGISTRY::HKEY_CLASSES_ROOT\OWC11.ChartSpace.11) -eq $False)
{
       Write-Host "This script requires Office Web Components to run correctly, please install these from the following website: http://www.microsoft.com/downloads/details.aspx?FamilyId=7287252C-402E-4F72-97A5-E0FD290D4B76&displaylang=en"
       exit
}
connect-VIServer yourserver

$Caption = "Datastore Usage %"

$categories = @()
$values = @()
$chart = new-object -com OWC11.ChartSpace.11
$chart.Clear()
$c = $chart.charts.Add(0)
$c.Type = 4
$c.HasTitle = "True"
$series = ([array] $chart.charts)[0].SeriesCollection.Add(0)

Get-datastore |Sort-Object FreeSpaceMB -Descending | foreach-object {

        $capacitymb = $_.CapacityMB
        $FreeSpaceMB = $_.FreeSpaceMB
        $UsedSpace = $capacitymb - $freespacemb

        $perc = $UsedSpace / $capacitymb * 100

        $categories += $_.Name
        $values += $perc * 1
}

$series.Caption = $Caption
$series.SetData(1, -1, $categories)
$series.SetData(2, -1, $values)
$filename = (resolve-path .).Path + "\Chart.jpg"
$chart.ExportPicture($filename, "jpg", 800, 500)
invoke-item $filename