Need some help with vmware powershell VM disks report.

Hi All,

I have powershell that lists VM name and its subsequent vmdk files along with datastore name. I need to add Get-VM’s property UsedSpaceGb in the report.


$VMsAdv = Get-VM | Sort-Object Name | % { Get-View $_.ID }
$myCol = @()
ForEach ($VMAdv in $VMsAdv)
ForEach ($Disk in $VMAdv.Layout.Disk)
$myObj = “” | Select-Object Name, Disk
$myObj.Name = $VMAdv.Name
$myObj.Disk = $Disk.DiskFile[0]
$myCol += $myObj


At present the report looks like below

Name Disk

VMname [Datastorename] VMName_1.vmdk

I would like it to be with VMName, Datastorename, Vmdk file name and Storage used by VMdk file in the report. Can anybody help me ?

Is there some way you can do “Get-VM | export clixml vm.xml” and share the vm.xml? A lot of people probably don’t have the get-vm command.

You can do it in a oneliner.

Get-VM | Select-Object -Property Name,@{E={([array]$_.HardDisks.filename)[0]};l='Disk'},UsedSpaceGB

If I remember correctly some attributes are only populated if and while VMTools are running.

I’m going to be so boring and suggest that you google for it.
Not to be mean or dismissive but depending on what you’re looking for it can be quite a long answer.
With a quick google I found multiple posts on vmware forum and blog posts elsewere.