Also don't try to shut down VM if it's already off, otherwise VSphere would raise an error: "The attempted operation cannot be performed in the current state (Powered off)."