I don't support this script, but if anybody else has a use for it, here it is.
This script, if given a "suspend" argument, will generate a list of running VMs, and suspend ONLY those VMs. If the script is given a "resume" argument, it will resume ONLY the VMs that it had suspended. This is handy since it doesn't resume VMs you had suspended before running the script. My intention is to run it as a Backup Exec pre / post command.
If anybody has suggestions for improving this script, speak up. I'm a novice.
If the developers would implement a "resume" function to vmware-cmd, instead of just a "start" function, I wouldn't have had to go through all this trouble. Great product, though.
__________________________
@echo off
REM
REM vmcontrol.bat
REM
REM This script will suspend and resume running VMs on VMWare Server. sed for windows is required: http://gnuwin32.sourceforge.net/packages/sed.htm
REM
REM Make sure we're given a proper command-line argument, else print syntax
IF "%1"=="suspend" GOTO Suspend
IF "%1"=="resume" GOTO Resume
GOTO Syntax
REM This section generates a list of running VMs as a text file, and suspends each one
:Suspend
REM clean up environment
del /Q c:\vmcontrol\vmconfigs.txt 2> NUL
del /Q c:\vmcontrol\vmfolders.txt 2> NUL
del /Q c:\vmcontrol\runningvmfolders.txt 2> NUL
del /Q c:\vmcontrol\runningvmconfigs.txt 2> NUL
REM Get a list of VM configs, encapsulate them in quotes with sed, and output the results to vmconfigs.txt
"C:\Program Files\VMware\VMware Server\vmware-cmd.bat" -l | c:\vmcontrol\sed\bin\sed -e s/^^/\"/ -e s/$/\"/> c:\vmcontrol\vmconfigs.txt
REM Parse vmconfigs.txt for folder names and output results to vmfolders.txt
For /F "delims=/" %%I in (c:\vmcontrol\vmconfigs.txt) do echo \^"%%dI%%pI^">> c:\vmcontrol\vmfolders.txt
REM Parse vmfolders.txt and look in each folder for a lock file. output matching folders to runningvmfolders.txt
For /F "delims=/" %%a in (c:\vmcontrol\vmfolders.txt) do if exist %%a*.lck echo %%a>> c:\vmcontrol\runningvmfolders.txt
REM Get a list of VM configs, and parse runningvmfolders.txt to find matching entries there. Output results to runningvmconfigs.txt
If Exist C:\vmcontrol\runningvmfolders.txt For /F "delims=/" %%a in (c:\vmcontrol\runningvmfolders.txt) do "C:\Program Files\VMware\VMware Server\vmware-cmd.bat" -l | find %%a|c:\vmcontrol\sed\bin\sed -e s/^^/\"/ -e s/$/\"/>> C:\vmcontrol\runningvmconfigs.txt
REM Run suspend command against configs in runningvmconfigs.txt
If Exist C:\vmcontrol\runningvmconfigs.txt For /F "delims=/" %%a in (c:\vmcontrol\runningvmconfigs.txt) do "C:\Program Files\VMware\VMware Server\vmware-cmd.bat" %%a suspend > NUL
REM Set ERRORLEVEL to 0. We don't want backup jobs to fail because of this script
set ERRORLEVEL=0
REM Exit the script here if called with "suspend" argument
GOTO End
REM This section resumes all configs previously placed in runningvmconfigs.txt by the suspend argument
:Resume
REM parse runningvmconfigs.txt and run a start command against each line
If Exist C:\vmcontrol\runningvmconfigs.txt For /F "delims=/" %%a in (c:\vmcontrol\runningvmconfigs.txt) do "C:\Program Files\VMware\VMware Server\vmware-cmd.bat" %%a start > NUL
REM Set ERRORLEVEL to 0. We don't want backup jobs to fail because of this script
set ERRORLEVEL=0
REM Exit the script here if called with the "resume" argument
GOTO End
REM This section prints syntax if no arguments or the wrong argrumts are given
:Syntax
echo %0 \^<suspend|resume>
REM This section is a target to skip other sections and exit the script
:End