2 Replies Latest reply on Oct 14, 2008 3:04 PM by kattrap

    VMs and Disk Files

    jpoling Expert

       

      I am still a newbie with this. . .is there a command (or pipeline) I can use to list my VMs and the size of the associated disk files?

       

       

       

       

       

      Thanks,

       

       

       

       

       

      Jeff

       

       

        • 1. Re: VMs and Disk Files
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          That info is available.

          The simplest method is like this:

          Get-VM | Get-Harddisk
          

           

          If you need specific info you can pipe the output to for example the Select-Object cmdlet.

          Or if you want only specific entries you can filter the output with Where-Object cmdlet.

           

          The possibilities are endless with PowerShell.

          As an example, the following line list the name of the guest, the name of the hard disk and the size of the hard disk in KB

          Get-VM | %{$_ | Tee-Object -variable vm | Get-HardDisk | %{Write-Host $vm.Name $_.Name $_.CapacityKB}}
          

           

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: VMs and Disk Files
            kattrap Enthusiast

             

            I'm not sure yet where the disconnect is, but your second (fancy) way to get the disk sizes is not correctly parsed for some of my VMs. For example, I have a VM with three vmdks, two are on one lun and the third is on a seperate lun.The second listing shows the correct values for the second and third disk (2.5GB and 329GB).

             

             

            Get-VM | %{$_ | Tee-Object -variable vm | Get-HardDisk | %{Write-Host $vm.Name $_.Name $_.CapacityKB}}

             

             

            mrs1 Hard Disk 1 8388608

            mrs1 Hard Disk 2 4718592

            mrs1 Hard Disk 3 16777216

             

             

            Get-VM | Get-HardDisk | select capacityKB,filename

             

             

            8388608    mrs1/mrs1.vmdk

            2621440    mrs1/mrs1_1.vmdk

            344981504    mrs1/mrs1.vmdk

             

             

            Previous to working with powershell (as I am a PS n00b), we were just running du on a host, pointing at the vmfs areas

             

             

            du -sh /vmfs/volumes/DATASTORE/

             

             

             

             

             

            LucD, if you have any ideas as to why the wacky numbers I would love to hear it. 

             

             

            ---

             

             

            datastore names have been altered to proctect the innocent.