Home > Blogs > VMware PowerCLI Blog

New Nested Properties for Navigating to Parent Objects in PowerCLI 4.1

While automating with PowerCLI scripts, you have most probably stumbled upon a situation when you need to access the parent of an object – the virtual machine of a CD drive, the host of virtual machine, the cluster of a host etc. In PowerCLI 4.0 U1 all object types which have “parents” are enhanced with the “Parent ID” property. Using this property you can easily get the parent object by invoking the corresponding Get-* cmdlet and filtering by ID. In the latest PowerCLI 4.1 release these “child” object types are enhanced with an even more useful nested property which holds the parent object itself. Using the nested parent object you can access the parent right away without the need to invoke an additional Get-* cmdlet.

Here is a simple example that illustrates the reference to the parent objects in PowerCLI. Let’s assume you have retrieved a virtual machine from your environment and for some troubleshooting reason, you need to check the time zone of the host where the virtual machine is running on. To do it, you have to access the host (parent object) of the virtual machine and get the value of its Timezone property.

Here is how this simple scenario can be achieved with PowerCLI 4.0 U1 by using the “VMHostID” property of the virtual machine object:

> $vm = Get-VM -Name "myVM" -Location "MyCluster"

> (Get-VMHost -ID $vm.VMHostId).Timezone

In PowerCLI 4.1 a new “VMHost” property is introduced to the “VirtualMachine” type to hold the reference to the object’s parent. So, now you can simply navigate from the virtual machine object to the time zone property of its host and no explicit retrieval with Get-VMHost is necessary:

> $vm = Get-VM -Name "myVM" -Location "MyCluster"

> $vm.VMHost.Timezone

    In addition to the child-to-parent relationship, nested properties are also used to represent another type of relationship: objects which are uniquely identified with another object. For example, besides the new “Parent” property, the “VMHost” type now has “StorageInfo”, “NetworkInfo”, “VMSwapfileDatastore”, “DiagnosticPartition”, and “FirewallDefaultPolicy” properties which let you know a whole lot more about a virtual machine host by just navigating through these properties. The new nested properties are initialized on demand, i.e. they will not be populated until the first time you access them, so no performance loss is expected when retrieving an object which has a parent property. Note that in future releases we’ll deprecate the old “Parent ID” properties so stick to nested properties when you need to access an object’s parent.

    I hope you’ll find the new nested properties useful and will start using them in your scripting activities J



Irina Nikolova


2 thoughts on “New Nested Properties for Navigating to Parent Objects in PowerCLI 4.1

Leave a Reply

Your email address will not be published. Required fields are marked *