Hi Mohamed,
I don't have a finished script for you, but here are the commands that you need to use:
vim-cmd vmsvc/getallvms
(will list all registered VMs with their "vmid" in the first column)
vim-cmd vmsvc/power.getstate vmid
(get the power state of a VM)
vim-cmd vmsvc/power.shutdown vmid
(shut down a VM through VMware Tools)
vim-cmd vmsvc/power.off vmid
(power off a VM. Use this after a shutdown via VMTools was not successful)
I hope this helps
Andreas