VMware Cloud Community
drivera01
Enthusiast
Enthusiast
Jump to solution

VM - actual disk usage (report)

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 Smiley Happy

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

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)}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

drivera01
Enthusiast
Enthusiast
Jump to solution

Cool!!!

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

Total diskspace used for all vms is:

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

drivera01
Enthusiast
Enthusiast
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

drivera01
Enthusiast
Enthusiast
Jump to solution

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)))

0 Kudos