VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Custom Property for Disk storage Format

I have a report that works like this:

get-vm | select name, memorygb,

@{N="GuestOS";E={$_.ExtensionData.Guest.guestFullName}}

What I would like to do is create a custom properties for each virtual disk on the VM.  The first custom property shows the name of the virtual disk, the second one whether it is thin or thick provisioned.  Some VMs have only one virtual disk.  Others have 2,3 or 4. 

How can I do this?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

foreach($vm in Get-VM){

    $obj = [ordered]@{

        Name = $vm.Name

        MemoryGB = $vm.MemoryGB

        GuestOS = $vm.ExtensionData.Guest.guestFullName

    }

    $i = 1

    Get-HardDisk -VM $vm | %{

        $obj.Add("HD$($i)Name",$_.Name)

        $obj.Add("HD$($i)Type",$_.StorageFormat)

        $i++

    }

    New-Object PSObject -Property $obj

}


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

foreach($vm in Get-VM){

    $obj = [ordered]@{

        Name = $vm.Name

        MemoryGB = $vm.MemoryGB

        GuestOS = $vm.ExtensionData.Guest.guestFullName

    }

    $i = 1

    Get-HardDisk -VM $vm | %{

        $obj.Add("HD$($i)Name",$_.Name)

        $obj.Add("HD$($i)Type",$_.StorageFormat)

        $i++

    }

    New-Object PSObject -Property $obj

}


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

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

ok great - thanks again

0 Kudos