The company I work for uses the vSphere API for all kinds of purposes. Usually this works great however one of our programs returned some errors after we moved a large number of VMs from one datastore to another.

It turns out that from vSphere API 5.0 onwards the VirtualMachineStorageInfo object is not always updated properly. The vSphere Web Services API documentation shows the following information about this issue.

Storage space used by the virtual machine, split by datastore. Can be explicitly refreshed by the RefreshStorageInfo operation. In releases after vSphere API 5.0, vSphere Servers might not generate property collector update notifications for this property. To obtain the latest value of the property, you can use PropertyCollector methods RetrievePropertiesEx or WaitForUpdatesEx. If you use the PropertyCollector.WaitForUpdatesEx method, specify an empty string for the version parameter. Any other version value will not produce any property values as no updates are generated.

To trigger the the RefreshStorageInfo operation that supposedly fixes the issue I wrote a simple PowerCLI function.

After you added this function to a PowerCLI session you can run it with an ‘Age’ parameter. This parameter determines the maximum age of the StorageInfo timestamp in hours. If the StorageInfo of a VM is older than the number of hours specified in the Age parameter it will be updated.

Share this if you found this interesting.

Leave a Reply

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