PowerCLI

 View Only
  • 1.  List VM name and sum of (provisioned) VM disk size and export it

    Posted Aug 01, 2013 03:05 PM

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

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



  • 2.  RE: List VM name and sum of (provisioned) VM disk size and export it

    Posted Aug 01, 2013 03:12 PM

    Hello,

    ProvisionedSpaceGB".  Like:

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

    How does that do for you?



  • 3.  RE: List VM name and sum of (provisioned) VM disk size and export it

    Posted Aug 01, 2013 03:57 PM

    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.



  • 4.  RE: List VM name and sum of (provisioned) VM disk size and export it
    Best Answer

    Posted Aug 01, 2013 05:02 PM

    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?



  • 5.  RE: List VM name and sum of (provisioned) VM disk size and export it

    Posted Aug 01, 2013 05:38 PM

    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.



  • 6.  RE: List VM name and sum of (provisioned) VM disk size and export it

    Posted Feb 02, 2016 08:44 PM

    Just the answer I was looking for - thanks!