PowerCLI: Virtual Machine Disk (VMDK) info v2: Analyze data with Excel
In my previous post about this subject I created a script to view the information on the PowerCLI console. With the v2 script you are able to export the data to a CSV file.
$myCol = @() $vms = get-view -ViewType VirtualMachine | Where-Object ` {-not $_.config.template} foreach($vm in $vms){ foreach($dev in $vm.config.hardware.Device){ $MYInfo = "" | Select-Object VMName, DeviceLabel, ` FileName, DiskMode, ThinProvisioned $MYInfo.VMName = $vm.Name if($dev.GetType().Name -eq "VirtualDisk"){ $MYInfo.DeviceLabel = $dev.DeviceInfo.Label $MYInfo.FileName = $dev.Backing.FileName $MYInfo.DiskMode = $dev.Backing.DiskMode if($dev.Backing.ThinProvisioned){ $MYInfo.ThinProvisioned = "True"} else{$MYInfo.ThinProvisioned = "False"} $myCol += $MYInfo } } } $myCol | Export-CSV -NoTypeInformation "D:\scripts\vmdkinfo.csv"
When the script is finished, you can import the CSV file into Excel. After the import, we can analyze the data with just a simple filter. With a few clicks, you’re able to view al the VM’s without Thin Provisioned disks.
Now we have a list with all the VM’s with Thin Provisioned disks:
So with a small PowerCLI script and the help of Microsoft Excel, you’re able to generate a report with just the information you need. The best part is that it will only cost you couple of minutes of your time
.
Categories: VMware
Excel, PowerCLI, Thin Provisioning, VMDK




A quick trick to get this straight into Excel:
; ii filename.csv
Or:
| export-csv -notype -file file.csv; ii file.csv
Great code,
I have few more additions to do, but don’t know how
How to get Filesize for that filename
and which ESX host that VM belongs
VM-Host gives me that, but how do I extend this CSV files so I have everything in online.
VMNAME, Device Label, FileName, FileSize, ESXHost, DiskMode, ThinProvisioned
@Rash:
Have you found this out? I was exactly looking for info on adding host and VMDK size to the list and am not yet confident enough in scripting to add it myself.
PS: Found the script in Virtu-Al.net VESI pack.
Have found out how to add the filesize to this list or at least the version of this script that comes with the Virtu-Al.net VESI pack. Shouldn’t be much difference.
One line needs to be changes, and one line is added.
Add “CapacityInKB” into the Select-Object list:
$MYInfo = “” | Select-Object VMName, DeviceLabel, `
FileName, CapacityInKB, DiskMode, ThinProvisioned
And add this line after the “$MYInfo.FileName = $dev.Backing.FileName” line:
$MYInfo.CapacityInKB = $dev.CapacityInKB
Thanks go to the VESI Script Editor, it provides a great detail into the objects you can work with in Powershell. Great debugging tool!
Hope this helps!