How to Shutdown Vmware Esxi Server from a simple batch File

Forums Software How to Shutdown Vmware Esxi Server from a simple batch File

This topic contains 0 replies, has 1 voice, and was last updated by  Mirk2003 2 months, 2 weeks ago. This post has been viewed 190 times

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #3229

    Mirk2003
    Participant

    Here an example on how to shutdown a Vmware Server remotely from  a Batch file. This could be usefull as shutdown script for ups or for other reasons.

    First of all, you have to enable ssh on your ssh host:

    VmwareSSH

    I put both file in the c:\script of my pc

    Follow the first file:  shutdown.bat

    net use \\10.0.240.52 mypassword /u:administrator
    
    shutdown /s /m \\10.0.240.52 /t 1 /c "Shutting down for blackout" /d P:1:1
    
    putty -ssh [email protected] 22 -pw mypassword -m command.txt
    
    esxcli system maintenanceMode set -e true -t 0
    esxcli system shutdown poweroff -r "blackout"

    You have to put the file putty.exe into c:\script;  you can download it from internet.

    Now follow the file command.txt

    esxcli system maintenanceMode set -e true -t 0
    esxcli system shutdown poweroff -r "blackout"

    The first line of shutdown.bat:

    net use \\10.0.240.52  mypassword  /u:administrator

    is used to login to first VM (in this case I have just only one VM in my esxi environment but you need before to shutdown every VM otherwise you cannot shutdown your esxi host)

     

    The second line:
    shutdown /s /m \\10.0.240.52 /t 1 /c “Shutting down for blackout” /d P:1:1
    is used to remotely shutdown your first VM

     

    The third line is used to connect to the esxi host by ssh:
    putty -ssh [email protected] 22 -pw mypassword -m command.txt
    This Putty call the file command.txt where there are into two command line:

    The following command put the esxi host in maintainance mode
    esxcli system maintenanceMode set -e true -t 0

    The second line operate the shutdown of the esxi host:
    esxcli system shutdown poweroff -r “blackout”

     

    The only problem to shutdown the Vmware Esxi in this way is that at startup, you have manually exit from maintainance mode but I think that this batch could be usefull.

     

    0
    0
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.