VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

How to get Foldername and size of disk ?

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

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That worked... Thank you very much 🙂

0 Kudos