1 2 Previous Next 20 Replies Latest reply on Oct 24, 2013 5:46 AM by TheVMinator

    Determining unused space in virtual hard disks

    TheVMinator Master

      I would like to determine the unused space in my virtual hard disks.  I would like to:

      • Select a vm
      • the first vmdk disk is always the OS disk in this environment.  How much space was provisioned, and how much is actually being used?

      • The other disk(s) are application data.  What is the total space provisioned on these non-os disks, and how much of this space is actually being used?

      thanks!

        • 1. Re: Determining unused space in virtual hard disks
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          To see what is actually used you will have to be able to map the OS partitions to the vDisks.

          And there is, afaik, no fool-proof way of doing that.

          For example, inside the guest you can find out how much space is used on the D-partition, but there is no sure way to know on which vDisk the D-partition is located I'm afraid.

           

          In some cases you could use the disksize you see inside the guest OS for a disk, to map it to a vDisk.

          But if you have 2 vDisks of the same size, that will be much more difficult.

           

          Arnim did a great post on this in his PowerCLI: Match VM and Windows harddisks – Part 2

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          1 person found this helpful
          • 2. Re: Determining unused space in virtual hard disks
            TheVMinator Master

            OK thanks for the info.  But just to be clear:

             

            - When I look in the vSphere client, it shows for each vmdk either "Harddisk 1" or "harddisk 2".  Since all the VMs were created from standard templates, I know my OS disk is always "Harddisk 1".  Is it not possible to pull the "harddisk 1" field using powercli, and select on that?  If I could do that, then I would always know I'm looking at an OS vmdk.

            • 3. Re: Determining unused space in virtual hard disks
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              Yes, you can select on the harddiskname.

              But the problem comes when you want to link this to the properties you have in $vm.Guest.Disks.

              That data is collected by the VMware Tools inside the guest OS.

              It will show the capacity and the freespace for partition C:, but it will not tell you which harddisk that is.

               

              And you are correct, In your situation, the C partition will always be Hard disk 1.

              But that doesn't work if you have more harddisks connected to the VM

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Determining unused space in virtual hard disks
                TheVMinator Master


                OK thanks.  If I always know that even if my VM has 5 vmdks, that the OS disk is always the first one that was created, and that the OS disk is always on the "C:" partitition and therefore is always "harddisk 1", wouldn't I be able to select "harddisk 1" and calculate the provisioned size of the vmdk vs. the amount of data actually used?  I would know that that is the amount of data used by my OS vmdk right?

                 

                For the other harddisks, I'm not concerned about knowing what the windows partition letter is.  I know any other harddisk other than 1 is data, not OS.  So if I total all other harddisks other than "harddisk 1", I know I'm getting the total of my data.

                 

                Am I thinking correctly?

                • 5. Re: Determining unused space in virtual hard disks
                  LucD Guru
                  vExpertCommunity WarriorsUser Moderators

                  Correct, just remember you need to have the VMware Tools installed to be able to retrieve the disk usage.

                   

                  You could do something like this

                   

                  Get-VM  |
                  Select Name,
                   
                  @{N="System disk capacity";E={
                     
                  $_.HardDisks | Where {$_.Name -eq "Hard disk 1"} |
                     
                  Select -ExpandProperty CapacityGB
                    }}
                  ,
                   
                  @{N="System disk used";E={
                     
                  $hdC = $_.Guest.Disks | Where {$_.Path -eq "C:\"}
                      [
                  math]::Round(($hdC.CapacityGB - $hdC.FreeSpaceGB),1)
                    }}
                  ,
                   
                  @{N="Other disks capacity";E={
                     
                  $_.HardDisks | Where {$_.Name -ne "Hard disk 1"} |
                     
                  Measure-Object -Property CapacityGB -Sum |
                     
                  Select -ExpandProperty Sum
                    }}
                  ,
                   
                  @{N="Other disks used";E={
                      [
                  math]::Round(($_.Guest.Disks | Where {$_.Path -ne "C:\"} | %{
                       
                  $_.CapacityGB - $_.FreeSpaceGB
                      }
                  | Measure-Object -Sum |
                     
                  select -ExpandProperty Sum),1)
                    }}
                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  1 person found this helpful
                  • 6. Re: Determining unused space in virtual hard disks
                    TheVMinator Master

                    OK thanks.  The only problem is that the system disk used column is blank for every vm when I run the report.  However, the "other disks used" has a value for every vm and is fine.  Any ideas on why this is?

                    • 7. Re: Determining unused space in virtual hard disks
                      LucD Guru
                      vExpertUser ModeratorsCommunity Warriors

                      Could it be that the Path property is not filled in correctly on your VMs ?

                      Do you see a C:\ path when you do this for one of the VMs that has a blank entry in that column ?

                       

                      Get-VM -Name MyVM | %{

                         $_.Guest.Disks

                      }

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: Determining unused space in virtual hard disks
                        TheVMinator Master

                        I ran the script you recommended using the name of a VM that has a blank field in "System Disk Used":

                         

                        Get-VM -Name MyVM | %{

                           $_.Guest.Disks

                        }

                         

                        but it doesn't give any output at all.

                        If I run

                        get-vm -name MyVM | get-harddisk

                        It shows the filenames though

                         

                        Any ideas?

                        Thanks again.

                        • 9. Re: Determining unused space in virtual hard disks
                          TheVMinator Master

                          (In fact the result is the same for every VM in the environment - none of them return a value for "system disk used")

                          • 10. Re: Determining unused space in virtual hard disks
                            LucD Guru
                            Community WarriorsvExpertUser Moderators

                            And you have the VMware Tools installed and running on all these VMs ?

                            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                            • 11. Re: Determining unused space in virtual hard disks
                              TheVMinator Master

                              There are some that VMware tools are not installed on like some proprietary linux distributions.  But 95% have vmware tools installed and running.  However, of a set of over 100 vms,  none of them are able to pull the field though.

                              • 12. Re: Determining unused space in virtual hard disks
                                LucD Guru
                                Community WarriorsUser ModeratorsvExpert

                                And I assume the following also returns nothing ?

                                Get-VM MyVM | Get-VMGuest | select -ExpandProperty Disks

                                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                • 13. Re: Determining unused space in virtual hard disks
                                  TheVMinator Master

                                  Actually, when I do that it shows me capacityGB, FreepaceGB and Path, for both C:\ and d:\ partitions.

                                  • 14. Re: Determining unused space in virtual hard disks
                                    LucD Guru
                                    User ModeratorsCommunity WarriorsvExpert

                                    Do you then get the results when you run this adapted version ?

                                    Get-VM  |

                                    Select Name,

                                      @{N="System disk capacity";E={

                                        $_.HardDisks | Where {$_.Name -eq "Hard disk 1"} |

                                        Select -ExpandProperty CapacityGB

                                      }},

                                      @{N="System disk used";E={

                                        $hdC = Get-VMGuest -VM $_ | %{$_.Guest.Disks} | Where {$_.Path -eq "C:\"}

                                        [math]::Round(($hdC.CapacityGB - $hdC.FreeSpaceGB),1)

                                      }},

                                      @{N="Other disks capacity";E={

                                        $_.HardDisks | Where {$_.Name -ne "Hard disk 1"} |

                                        Measure-Object -Property CapacityGB -Sum |

                                        Select -ExpandProperty Sum

                                      }},

                                      @{N="Other disks used";E={

                                        [math]::Round((Get-VMGuest -VM $_ | %{$_.Guest.Disks} | Where {$_.Path -ne "C:\"} | %{

                                          $_.CapacityGB - $_.FreeSpaceGB

                                        } | Measure-Object -Sum |

                                        select -ExpandProperty Sum),1)

                                      }}

                                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                    1 2 Previous Next