VI Toolkit One-Liner: VM Guest Disk Sizes

A Simple One-liner today but it shows you how to add information along the pipe line to enable new properties which can be formed using other cmdlets or simple math statements on existing properties:

This one-liner will give you the VM disk or partition sizes for each of your VMs:

ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath, @{N="Capacity(MB)";E={[math]::Round($_.Capacity/ 1MB)}}, @{N="Free Space(MB)";E={[math]::Round($_.FreeSpace / 1MB)}}, @{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}



34 thoughts on “VI Toolkit One-Liner: VM Guest Disk Sizes”

  1. $report = ForEach ($VM in Get-VM ){
    ($VM.Extensiondata.Guest.Disk | Select
    @{N=”Data Center”;E={$vm | Get-Datacenter | Select-Object -ExpandProperty name }},
    @{N=”vCenter Server”;E={$vm.ExtensionData.Client.ServiceUrl.Split(‘/’)[2].trimend(“:443″)}},
    @{N=”Cluster”;E={$vm | Get-Cluster | Select-Object -ExpandProperty name}},
    @{N=”Capacity(MB)”;E={[math]::Round($_.Capacity/ 1MB)}},
    @{N=”Free Space(MB)”;E={[math]::Round($_.FreeSpace / 1MB)}},
    @{N=”Free Space %”;E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})
    $report | Export-Csv D:\SZEMMALI\scripts\vmware-collect\report.csv -NoTypeInformation -UseCulture

  2. Hi All,
    I tried the script and trying to export it in html, but the data is not coming in html.. can any one help me in that.

    ForEach ($VM in ( Get-VM |Get-View)){($info = $VM.Guest.Disk |Select @{N=“Name“;E={$VM.Name}},DiskPath, @{N=“Capacity(GB)“;E={[math]::Round($_.Capacity/ 1GB)}}, @{N=“Free Space(GB)“;E={[math]::Round($_.FreeSpace / 1GB)}}, @{N=“Free Space %“;E={[math]::Round(((100 * ($_.FreeSpace))/ ($_.Capacity)),0)}})|Format-Table} ConvertTo-Html | Set-Content C:\Users\ABC\Desktop\FreeSpaceFinal.htm

  3. hi
     i need some help
     im using this script for specific VMs in vApp
    ($VM in (Get-VApp “My vApp” | Get-VM |Get-View)){($VM.Guest.Disk
    |Select @{N=“Name“;E={$VM.Name}},DiskPath,
    @{N=“Capacity(GB)“;E={[math]::Round($_.Capacity/ 1GB)}}, @{N=“Free
    Space(GB)“;E={[math]::Round($_.FreeSpace / 1GB)}}, @{N=“Free Space
    %“;E={[math]::Round(((100 * ($_.FreeSpace))/
    i want to add “if” option that send me email when the “free Space %” is lower than 15
    please help

  4. I read about VI Toolkit, but cannot find a download URL anywhere.
    Can you give me an idea from where to obtain it?

  5. I am looking for a script that will list vmdk type (Thin, Lazy Zero Thick, Eager Zero Thick) for all the guests.

  6. you can get with this below script


    $AllVMs = Get-VM | Get-View | Where {-not $_.Config.Template}
    $SortedVMs = $AllVMs | Select *, @{N=”NumDisks”;E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks

    } | Out-GridView

    Disconnect-VIServer -Confirm:$False

  7. Connect-VIServer

    $AllVMs = Get-VM | Get-View | Where {-not $_.Config.Template}
    $SortedVMs = $AllVMs | Select *, @{N=”NumDisks”;E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks

    } | Out-GridView

    Disconnect-VIServer -Confirm:$False

  8. Alan,

    This is a one liner that works perfect.

    Get-VM | Where-Object {$_.Name -match “vmware”} | select Name , powerstate , Numcpu , memorymb

    but i wanted to add the “VM IP” and “VM creation date” to the same. is it possible?

  9. Hello friends,

    It’s really helping to my work, i want IP & HostName also can any one help me on this ?

    Thanks in advance.

  10. Hi there,

    Im trying to get this in an Script… which gets the Size and writes all VM’s with Free Diskspace less then an value in an HTML or textfile to E-Mail it…

    Anybody.. could help… started today with PowerCLI / Powershell
    For the E-Mail List I would like to use the Variable $users
    and for the WarningValue $percentofWarning…

    The E-Mail sending-sequenze using the Content of the txt/html is already done..

    Any ideas?


  11. Fantastic – Thanks very much – I’ve been trying (and not getting very far) to put something like this together.

    Question – Is it overly complicated to add additional code to update the annotation field for each VM with this information?


  12. Yes there is a way but i doubt it will be a one-liner, I will try and work on it when I get 5 mins 🙂

  13. Hello Al,

    You script(oneliner) works great for windows guests but only shows the Boot volume for a Linux machine, do you know a way how to list the VMDK sizes for a Linux VM ?


  14. @Albert Widjaja

    Apparently this is a bit of an issue with PowerGui, if you are running this through the PowerGui editor then try running it by pushing Ctrl + F5 rather than just F5 or pushing the play button. (Thanks LucD)

    Hope that helps.


  15. Dear Sir,

    Thanks for creating and sharing such a great cmdlet, however when
    I execute your script in PowerGUI

    after specifying: Connect-VIServer ESXi1

    i got error:
    Operation is not valid due to the current state of the object.
    At :line:0 char:0

    is it because I’m running ESXi 3.5 u4 ?


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.