You can configure a virtual machine to use VMware Tools to run scripts before or after virtual machine power operations.
Scripts run only before or after "soft" power operations. For example, if you power off a virtual machine, as opposed to shutting down the guest operating system, the configured script does not run.