inside /var/spool/cron/crontabs/root
add the following line
*/5 * * * * vim-cmd vmsvc/power.getstate 5 | grep "Powered off" && vim-cmd vmsvc/power.on 5
Useful commands:
List all VMs
`vim-cmd vmsvc/getallvms`
Get the power status of a particular vm
`vim-cmd vmsvc/power.getstate 5`
this will return ether "Powered on" or "Powered off"
eg:
Retrieved runtime info
Powered on
(Source: https://vswitchzero.com/2021/02/17/scheduling-tasks-in-esxi-using-cron/)