Hi,
Please help, I am unable to get Foldername and Disk size of the VMDK from below, please help
$VMsAdv = Get-VM | Sort-Object Name | % { Get-View $_.ID } $myCol = @() ForEach ($VMAdv in $VMsAdv) { ForEach ($Disk in $VMAdv.Layout.Disk) { $myObj = "" | Select-Object Folder, Name, Disk, DiskSize
$myObj.Folder = $VMAdv.Folder $myObj.Name = $VMAdv.Name $myObj.Disk = $Disk.DiskFile[0]
$myObj.DiskSize = $Disk.CapacityInGB $myCol += $myObj } } $myCol | ft -auto
You are using the VirtualMachine object (through Get-View), which is not the same as the object returned by Get-VM.
You could do
Get-VM -PipelineVariable vm | Get-HardDisk |
Select @{N='Folder';E={$vm.Folder.Name}},
@{N='Name';E={$vm.Name}},
@{N='Disk';E={$_.FileName}},
@{N='DiskSize';E={$_.CapacityGB}} |
Sort-Object -Property Name |
Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are using the VirtualMachine object (through Get-View), which is not the same as the object returned by Get-VM.
You could do
Get-VM -PipelineVariable vm | Get-HardDisk |
Select @{N='Folder';E={$vm.Folder.Name}},
@{N='Name';E={$vm.Name}},
@{N='Disk';E={$_.FileName}},
@{N='DiskSize';E={$_.CapacityGB}} |
Sort-Object -Property Name |
Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That worked... Thank you very much 🙂