-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSuspendRunningVMs.bat
47 lines (39 loc) · 1.18 KB
/
SuspendRunningVMs.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@echo off
echo SuspendRunningVMs Command (x64)...
REM https://stackoverflow.com/questions/20691060/echo-a-blank-empty-line-to-the-console-from-a-windows-batch-file
echo(
echo Ideas for improving this? Visit https://github.com/fatso83/vmware-auto-suspend
echo(
echo(
SETLOCAL
REM Specify where vmrun.exe can be located
SET WSPath="C:\Program Files (x86)\VMware\VMware Workstation"
REM Get the list of currently running VMs
%WSPath%\vmrun.exe list > %temp%\vmlist.txt
REM Suspend all running VMs
FOR /F "delims=* skip=1" %%v IN (%temp%\vmlist.txt) DO CALL :SuspendVM "%%v"
:WaitLoop
echo Waiting for the VMs to suspend...
REM Pause until no more VMs are running
%WSPath%\vmrun.exe list | FIND "Total running VMs: 0"
IF NOT ERRORLEVEL 1 GOTO End
timeout /t 5/nobreak
GOTO WaitLoop
:End
echo End of script; all VMs suspended.
ENDLOCAL
GOTO :EOF
REM Suspend a VM
:SuspendVM
echo Suspending VM %1
%WSPath%\vmrun.exe suspend %1
REM Allow some time after suspend call (allow disk to write vmem).
echo Wait a little bit for the VM to commit...
timeout /t 10 /nobreak
GOTO :EOF
REM Resume a VM (not used now, but may have use in future)
:ResumeVM
echo Starting VM %1
%WSPath%\vmrun.exe start %1
GOTO :EOF
:EOF