VMware Cloud Community
tdubb123
Expert
Expert

get-vm and hard disk

Trying to get a list of VMs and their hard disk (vmdk ) sizes and USedspace and provisioned space

get-content vm.txt | % {get-vm $_* | Get-HardDisk | select Parent, Name, CapacityGB } | ft -AutoSize

this works but how do I get the Usedspace and provisoned space as well?

0 Kudos
5 Replies
tdubb123
Expert
Expert

any idea why I am only getting one line in my csv?

PS C:\powershell> get-content vms.txt | %{ get-vm $_*  | Get-HardDisk | select PArent, NAme, CapacityGB } | Export-Csv C:\powershell\vm_diskinfo2.csv

0 Kudos
vXav
Expert
Expert

At each loop you overwrite the content of the CSV. Try adding -Append to your Export-CSV.

For the guest used space you can find it in (get-vm).Guest.Disks but to do the link with the actual hard disk you need to interact with the guest OS.

Check this post : PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

0 Kudos
tdubb123
Expert
Expert

how do I combine

NAme, hard disk 1, hard disk 2, provisionedspacedb and usedspacegb?

0 Kudos
tdubb123
Expert
Expert

when I look at my VM, I see this with get-harddisk

Screen Shot 2016-11-11 at 1.07.05 PM.png

but get-vm shows this for Provisionedspacegb

Screen Shot 2016-11-11 at 1.07.58 PM.png

why isnt it 50gb instead ? where is 54.9 coming from?

0 Kudos
LucD
Leadership
Leadership

ProvisionedSpaceGB is the total of all the used storage space by the VM, not only the HardDisk space.

This number includes the VMX, the swap file, the logs...

You can do something like this, but the Provisioned and Used is only maintained per VM, not per harddisk.

To get the provisioned and used per datastore, you will have to actually look at the files that constitute a harddisk.

Note that the Export-Csv takes the first element in an array to determine how many columns there will be in the CSV, hence the descending sort per number of properties, before the export.

$report = Get-VM | %{

    $obj = New-Object PSObject -Property @{

        VM = $_.Name

        ProvisionedGB = $_.ProvisionedSpaceGB

        UsedGB = $_.UsedSpaceGB

    }

    $i = 1

    Get-HardDisk -VM $_ | $%{

        $obj | Add-Member -MemberType NoteProperty -Name "HD$($i)" -Value $_.CapacityGB

        $i++

    }

    $obj

}

$report | Sort-Object -Property {($_ | Get-Member -MemberType NoteProperty).Count} -Descending |

Export-Csv report.csv -NoTypeInformation -UseCulture


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

0 Kudos