Update Custom Property Field in VMM with the Last Update Date

We recently added four custom fields to Virtual Machine Manager (VMM) to help us keep track of application owners, server owners, when in our patch schedule servers were being updated, and the last time a server was updated.  In order to keep the field for last update current, I wrote a script to get the date the server was last updated, compare it to the value currently in the field, and if the new date was later than the value in the custom property, to change it.  Now there are certainly some issues with this script that need improving.  The main issue being that if there are multiple updates with different update days, it doesn’t pick out each unique one, or the latest one, and so updates the property in VMM multiple times.  I have this script running as a scheduled task on the VMM server once a week and it is working great.