image

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.

image

Now we have a list with all the VM’s with Thin Provisioned disks:

image 

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 🙂 .

Advertisement

16 thoughts on “PowerCLI: Virtual Machine Disk (VMDK) info v2: Analyze data with Excel

  1. 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

    1. @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.

  2. 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!

  3. Change the line $vms = Get-View Viewtype……. to

    $vms = get-content D:\vms.txt
    foreach($i in $vms){
    $vm = Get-VM $i | Get-View

    vms.txt will look like this:

    vm1
    vm2
    vm3
    etc.

    Good luck

  4. That helped but didn’t work.
    I modified it to this and its ok now.
    $vms = get-content “h:\scripts\Vmlist.txt”|foreach-object {Get-VM $_ | Get-View}

    A little slow, I’m thinking it would be quicker to do a Get-View once as you do before, and then operate the rest of the script if the name exists in the list.

    Thanks lot for help nevertheless.

    1. The solution above was a quick and dirty solution. This solution is a lot faster:

      $vms = Get-Content “X:\vms.txt”
      foreach($name in $vms){
      $vm = Get-View -ViewType VirtualMachine -Filter @{“Name” = $name}

      Good luck!

  5. The output has just one vm, when I have 5. Its last one in foreach list.

    Had another tinker around and ended up with this, it takes only a couple seconds to complete now. 🙂

    $vmlist = Get-Content “h:\scripts\Vmlist2010.txt”
    $vms=$vmlist|foreach { Get-View -ViewType VirtualMachine -Filter @{“name” = “$_”}}

    Now i want to add more objects, like mem/cpu etc. Will check the Vesi Editor. Is that the best place to find them?

    Thanks again, you really got me on the right track!

  6. Thanks for the script, with some pretty heavy wrapping and customization for my purposes, I’ve got it exporting object-oriented, per-VM XML instead of a flat CSV.

    I can send you my version if you like.

    Jeff: It shouldnt be too hard to add information on RDM info, I’ll see if I can work that out tomorrow.

    -Doug (Cnidus)

  7. This is a nice utility. Ran across 3 vCenters and about 24 ESX/ESXi Hosts in two physical datacenters in just a few seconds. Thanks.

  8. thats a very good command to get the vdisk info, but I’d need few more info –> free space and total disk space used and volume name like – C:\, D:\ drive etc…

    Output should look like

    VMname Disk Path Disk capacity Disk Free space Device Label Datastore Disk filename Disk mode Thin provisioned
    VM01 C:\ 30GB 15GB Hard disk 1 DT-R5-OS01 VM01/VM01.vmdk persistent False
    VM01 D:\ 40GB 10GB Hard disk 2 DT-R1-ST01 VM01/VM02.vmdk persistent True

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.