• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Yellow Bricks

by Duncan Epping

  • Home
  • Unexplored Territory Podcast
  • HA Deepdive
  • ESXTOP
  • Stickers/Shirts
  • Privacy Policy
  • About
  • Show Search
Hide Search

shutdown all vm’s and ESX

Duncan Epping · Jun 16, 2008 ·

Just dropped the following short script in a topic on the VMTN Community. It shuts down every VM on the host and than the host itself, but it will enter maintenance mode first, just to be sure that no other vm’s get migrated to this host.

VMLIST=’vmware-cmd -l’
for config in ${VMLIST}
do
vmware-cmd $config stop trysoft
done
vimsh -n -e /hostsvc/maintenance_mode_enter
shutdown -h now

addition: thanks forbes for the trysoft addition.

Related

Server ESX, Scripting, VMware

Reader Interactions

Comments

  1. Forbes Guthrie says

    16 June, 2008 at 16:55

    Hi Duncan, nice little script to have on each host.

    I would add the “trysoft” to this line:

    vmware-cmd ${VMLIST} stop trysoft

    otherwise I think it will just send a soft power-off to the VMs. I believe the trysoft will do the same, but then hard power-off if the soft doesn’t work.

    Forbes.

  2. Andrew Gallop says

    15 July, 2008 at 09:37

    Hi Duncan,

    Apologies if this is a somewhat uneducated question. Could this script be initiated by UPS software to power down the VMs and host in the event of a power failure?

    Regards,
    Andrew

  3. Duncan Epping says

    15 July, 2008 at 10:39

    Yeah why not. But I wouldn’t place it into maintenance mode because VM’s will not startup when the server is in maintenance mode, or you would have to script a ” leave maintenance mode” .

  4. Christos Myrsakis says

    10 September, 2008 at 13:54

    hi guys

    how do i execute this script? do i save it as a vbs and run it? How can i launch this from a batch file?

    Finally i didn’t quite understand what are the changes required ti implment Forbes’ suggestion.

    Many Thanks

    Christos

  5. Duncan says

    10 September, 2008 at 14:38

    These changes already have been made, and its a bash script so run it from the service console

  6. Doug says

    15 January, 2009 at 20:43

    Scripting help. When using Remote CLI I receive “Can’t modify constant item in scalar assignment at line 2”. Any ideas?

  7. asdf says

    12 February, 2009 at 08:27

    not working

    [2009-02-11 23:29:51.328 ‘App’ 3076468864 info] Current working directory: /usr/lib/vmware/hostd
    [2009-02-11 23:29:51.329 ‘BaseLibs’ 3076468864 info] HOSTINFO: Seeing AMD CPU, numCoresPerCPU 2 numThreadsPerCore 1.
    [2009-02-11 23:29:51.332 ‘BaseLibs’ 3076468864 info] HOSTINFO: hyperthreading disabled, setting number of threads per core to 1.
    [2009-02-11 23:29:51.332 ‘BaseLibs’ 3076468864 info] HOSTINFO: This machine has 4 physical CPUS, 8 total cores, and 8 logical CPUs.
    [2009-02-11 23:29:51.429 ‘BaseLibs’ 3076468864 info] System libcrypto.so.0.9.7 library is older than our library (90701F < 90709F)
    [2009-02-11 23:29:51.429 ‘App’ 3076468864 info] Vmacore::InitSSL: doVersionCheck = true, handshakeTimeoutUs = 120000000
    Failed to connect: 514 Error connecting to hostd-vmdb service instance.
    Not connected.
    Not connected.

  8. Duncan Epping says

    12 February, 2009 at 08:55

    i’ve updated the scripts, please try again…

  9. uli says

    9 September, 2009 at 13:05

    Hi to all,
    the script is ok but my virtual machines has a space in the name and the script does not works.

    Someone can help me?

    Thanks

  10. goomior says

    26 October, 2009 at 17:03

    uli, try this one:

    vmware-cmd -l | while read i
    do
    vmware-cmd $i stop trysoft
    done

    You may also use “if” and “vmware-cmd $i getstate” to prevent powering of already powered-off machines.

  11. Vamsi says

    7 September, 2012 at 09:49

    Hello All,

    Is there any way to stop only specific vms from the list of input file?

    Thanks

Primary Sidebar

About the Author

Duncan Epping is a Chief Technologist and Distinguished Engineering Architect at Broadcom. Besides writing on Yellow-Bricks, Duncan is the co-author of the vSAN Deep Dive and the vSphere Clustering Deep Dive book series. Duncan is also the host of the Unexplored Territory Podcast.

Follow Us

  • X
  • Spotify
  • RSS Feed
  • LinkedIn

Recommended Book(s)

Also visit!

For the Dutch-speaking audience, make sure to visit RunNerd.nl to follow my running adventure, read shoe/gear/race reviews, and more!

Do you like Hardcore-Punk music? Follow my Spotify Playlist!

Do you like 80s music? I got you covered!

Copyright Yellow-Bricks.com © 2026 · Log in