Automation

 View Only
  • 1.  VM - actual disk usage (report)

    Posted May 01, 2014 03:34 AM

    Hi,

    I probably already know the answer but you guys surprise me sometimes what you can do.

    I have a bunch windows and linux vms.

    is it possible to run a report to see what amount of disk-usage each vm is using. So what i mean is if the VM has  multiple vmdks that add up to 100g, but the vm itself is only using 30gb at the OS level. is there a way to capture that info and export it out?

    I honestly think not, but i'm asking anyways :smileyhappy:



  • 2.  RE: VM - actual disk usage (report)

    Posted May 01, 2014 05:00 AM

    Provided you have the VMware Tools installed, you can do something like this

    Get-VM |
    Select Name,
    @{N="HD Used (GB)";E={[math]::Round(($_.Guest.Disks | %{
         
    $_.CapacityGB - $_.FreeSpaceGB} | Measure-Object -Sum |
         
    Select -ExpandProperty Sum),1)}}


  • 3.  RE: VM - actual disk usage (report)

    Posted May 01, 2014 06:15 PM

    Cool!!!

    Anyway to total it up at the end, for all vms?

    Total diskspace used for all vms is:



  • 4.  RE: VM - actual disk usage (report)

    Posted May 01, 2014 06:31 PM

    Try something like this

    $report = Get-VM |
    Select Name,
    @{N="HD Used (GB)";E={[math]::Round(($_.Guest.Disks | %{
         
    $_.CapacityGB - $_.FreeSpaceGB} | Measure-Object -Sum |
         
    Select -ExpandProperty Sum),1)}}
    $report += ("" | Select @{N="Name";E={"Total space"}},
     
    @{N="HD Used (GB)";E={$report | Measure-Object -Property "HD Used (GB)" -Sum | Select -ExpandProperty Sum}})

    $report


  • 5.  RE: VM - actual disk usage (report)

    Posted May 02, 2014 03:35 AM

    LucD,

    So I would like to change it up a bit and catch the info so I can report it in a report like this:

    The problem is I don’t know what extensions would be for the items for the disk.. cause these don’t appear to work ☹

    $Report = @()

    Get-Cluster MYCLUSTER |get-vm MYVM | % {

    $vm = Get-View $_.ID

    $ReportRow = "" | Select-Object VMName,DiskCapacity,DiskFreespace

    $ReportRow.VMName = $vm.Name

    $ReportRow.DiskCapacity = $vm.extensiondata.guest.disk.capacity

    $ReportRow.DiskFreespace = $vm.extensiondata.guest.disk.freespace

    I need to do it this was cause this is the only way I know how to do it to make the report like this:

    I want to really have diskUSED field but I don’t know how to do that except on how you showed me, but I don’t know how to convert it to how I need it.

    Any help would be greatly appreciated!!!

    MYVM DISK USAGE

    VMName

    DiskCapacity

    DiskFreespace

    myvm



  • 6.  RE: VM - actual disk usage (report)
    Best Answer

    Posted May 02, 2014 05:01 AM

    You mean like this ?

    $Report = @()

    Get-Cluster Cluster |Get-VM | %{
     
    $ReportRow = "" | Select-Object VMName,DiskCapacity,DiskFreespace
     
    $ReportRow.VMName = $_.Name
     
    $ReportRow.DiskCapacity = $_.Guest.Disks | Measure-Object CapacityGB -Sum | Select -ExpandProperty Sum
     
    $ReportRow.DiskFreespace = $ReportRow.DiskCapacity - ($_.Guest.Disks | Measure-Object FreeSpaceGB -Sum | Select -ExpandProperty Sum)
     
    $Report += $ReportRow
    }

    $Report


  • 7.  RE: VM - actual disk usage (report)

    Posted May 02, 2014 05:35 PM

    Ok,

    Can you tell me why im getting a negative number because of my rounding I put in?

    $ReportRow."Total Free Space at Guest OS Level" = ::Round(($ReportRow.DiskCapacity - ($_.Guest.Disks | Measure-Object FreeSpaceGB -Sum | Select -ExpandProperty Sum)))