VMware Cloud Community
MikkoJ
Enthusiast
Enthusiast
Jump to solution

List VM name and sum of (provisioned) VM disk size and export it

Hello,

I need to list all VM:s and their provisioned disk space. I can do it with this command:

get-vm * | foreach-object {write-host "$_`t" (Get-HardDisk -vm $_ | Measure-Object -Property CapacityGB -Sum).sum.ToString()}

(If there is more elegant way to do this, please feel free to enlight me Smiley Happy )

The problem is that I'm unable to export this data. Adding

| export-csv ... or

> list.txt

to end of line creates empty file and prints output to console.

How could I make export work correctly (or way I want)?

1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Ah, you are after the total size of just the VM's hard disks, not VMs' provisioned size on a datastore.  Then, yes, you could continue to use the Get-HardDisk cmdlet as you had in your first example, but written as such to allow for further operations on the result:

Get-VM | Select-Object Name,@{n="HardDiskSizeGB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}

This route may be somewhat slow, especially as your environment is larger.  If too slow, then we can employ everyone's bestest buddy, Get-View.

Anyway, does that do it for you?

View solution in original post

5 Replies
mattboren
Expert
Expert
Jump to solution

Hello,

ProvisionedSpaceGB".  Like:

Get-VM | Select-Object Name,ProvisionedSpaceGB | Export-Csv -NoTypeInformation -UseCulture c:\temp\myVMInfo.csv

How does that do for you?

0 Kudos
MikkoJ
Enthusiast
Enthusiast
Jump to solution

Hello,

thank you for the answer, unfortunately that does not help me. ProvisionedSpaceGB does not have correct value, for it has VM's hard disks, swap file and other configuration files.

I need just a size of disks, for we use that as a billing metric.

0 Kudos
mattboren
Expert
Expert
Jump to solution

Ah, you are after the total size of just the VM's hard disks, not VMs' provisioned size on a datastore.  Then, yes, you could continue to use the Get-HardDisk cmdlet as you had in your first example, but written as such to allow for further operations on the result:

Get-VM | Select-Object Name,@{n="HardDiskSizeGB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}

This route may be somewhat slow, especially as your environment is larger.  If too slow, then we can employ everyone's bestest buddy, Get-View.

Anyway, does that do it for you?

MikkoJ
Enthusiast
Enthusiast
Jump to solution

Thank you, this is exactly what I need. Speed is not issue, environment is quite small, just under 200 VM.

I'll look into Get-View anyway.

0 Kudos
MrSpo
Contributor
Contributor
Jump to solution

Just the answer I was looking for - thanks!

0 Kudos