First, I'm not going to make that code available (should I have some) in this forum.
This borders on, or even crosses, what is legal imho.
In any case you will sure need SSH access to the ESXi node for such a script.
And then some Google fu to find the procedure, should there be one.