使用vmrun批量创建虚拟机

1、vmrun路径

vmrun.exe路径在“C:\Program Files (x86)\VMware\VMware Workstation”文件夹中

C:\Program Files (x86)\VMware\VMware Workstation>vmrun /?

vmrun version 1.17.0 build-15018445

Usage: vmrun [AUTHENTICATION-FLAGS] COMMAND [PARAMETERS]

AUTHENTICATION-FLAGS

These must appear before the command and any command parameters.

-T (ws|fusion||player)
-vp
-gu
-gp

POWER COMMANDS PARAMETERS DESCRIPTION


start Path to vmx file Start a VM or Team
[gui|nogui]

stop Path to vmx file Stop a VM or Team
[hard|soft]

reset Path to vmx file Reset a VM or Team
[hard|soft]

suspend Path to vmx file Suspend a VM or Team
[hard|soft]

pause Path to vmx file Pause a VM

unpause Path to vmx file Unpause a VM

SNAPSHOT COMMANDS PARAMETERS DESCRIPTION


listSnapshots Path to vmx file List all snapshots in a VM
[showTree]

snapshot Path to vmx file Create a snapshot of a VM
Snapshot name

deleteSnapshot Path to vmx file Remove a snapshot from a VM
Snapshot name
[andDeleteChildren]

revertToSnapshot Path to vmx file Set VM state to a snapshot
Snapshot name

GUEST OS COMMANDS PARAMETERS DESCRIPTION


runProgramInGuest Path to vmx file Run a program in Guest OS
[-noWait]
[-activeWindow]
[-interactive]
Complete-Path-To-Program
[Program arguments]

fileExistsInGuest Path to vmx file Check if a file exists in Guest OS
Path to file in guest

directoryExistsInGuest Path to vmx file Check if a directory exists in Guest OS
Path to directory in guest

setSharedFolderState Path to vmx file Modify a Host-Guest shared folder
Share name
Host path
writable | readonly

addSharedFolder Path to vmx file Add a Host-Guest shared folder
Share name
New host path

removeSharedFolder Path to vmx file Remove a Host-Guest shared folder
Share name

enableSharedFolders Path to vmx file Enable shared folders in Guest
[runtime]

disableSharedFolders Path to vmx file Disable shared folders in Guest
[runtime]

listProcessesInGuest Path to vmx file List running processes in Guest OS

killProcessInGuest Path to vmx file Kill a process in Guest OS
process id

runScriptInGuest Path to vmx file Run a script in Guest OS
[-noWait]
[-activeWindow]
[-interactive]
Interpreter path
Script text

deleteFileInGuest Path to vmx file Delete a file in Guest OS
Path in guest

createDirectoryInGuest Path to vmx file Create a directory in Guest OS
Directory path in guest

deleteDirectoryInGuest Path to vmx file Delete a directory in Guest OS
Directory path in guest

CreateTempfileInGuest Path to vmx file Create a temporary file in Guest OS

listDirectoryInGuest Path to vmx file List a directory in Guest OS
Directory path in guest

CopyFileFromHostToGuest Path to vmx file Copy a file from host OS to guest OS
Path on host
Path in guest

CopyFileFromGuestToHost Path to vmx file Copy a file from guest OS to host OS
Path in guest
Path on host

renameFileInGuest Path to vmx file Rename a file in Guest OS
Original name
New name

typeKeystrokesInGuest Path to vmx file Type Keystrokes in Guest OS
keystroke string

connectNamedDevice Path to vmx file Connect the named device in the Guest OS
device name

disconnectNamedDevice Path to vmx file Disconnect the named device in the Guest OS
device name

captureScreen Path to vmx file Capture the screen of the VM to a local file
Path on host

writeVariable Path to vmx file Write a variable in the VM state
[runtimeConfig|guestEnv|guestVar]
variable name
variable value

readVariable Path to vmx file Read a variable in the VM state
[runtimeConfig|guestEnv|guestVar]
variable name

getGuestIPAddress Path to vmx file Gets the IP address of the guest
[-wait]

GENERAL COMMANDS PARAMETERS DESCRIPTION


list List all running VMs

upgradevm Path to vmx file Upgrade VM file format, virtual hw

installTools Path to vmx file Install Tools in Guest

checkToolsState Path to vmx file Check the current Tools state

deleteVM Path to vmx file Delete a VM

clone Path to vmx file Create a copy of the VM
Path to destination vmx file
full|linked
[-snapshot=Snapshot Name]
[-cloneName=Name]

Template VM COMMANDS PARAMETERS DESCRIPTION


downloadPhotonVM Path for new VM Download Photon VM

Examples:

Starting a virtual machine with Workstation on a Windows host
vmrun -T ws start “c:\my VMs\myVM.vmx”

Running a program in a virtual machine with Workstation on a Windows host with Windows guest
vmrun -T ws -gu guestUser -gp guestPassword runProgramInGuest “c:\my VMs\myVM.vmx” “c:\Program Files\myProgram.exe”

Creating a snapshot of a virtual machine with Workstation on a Windows host
vmrun -T ws snapshot “c:\my VMs\myVM.vmx” mySnapshot

Reverting to a snapshot with Workstation on a Windows host
vmrun -T ws revertToSnapshot “c:\my VMs\myVM.vmx” mySnapshot

Deleting a snapshot with Workstation on a Windows host
vmrun -T ws deleteSnapshot “c:\my VMs\myVM.vmx” mySnapshot

Enabling Shared Folders with Workstation on a Windows host
vmrun -T ws enableSharedFolders “c:\my VMs\myVM.vmx”

2、将vmrun添加到环境变量

计算机-属性-高级系统设置-高级-环境变量

重新运行命令提示符窗口运行vmrun查看环境变量是否配置成功

3、编辑模板

vmrun -T ws start “E:\2008R2\Windows Server 2008.vmx” 启动WS2008虚拟机
vmrun -T ws stop “E:\2008R2\Windows Server 2008.vmx” 关闭WS2008虚拟机
vmrun -T player start “E:\2008R2\Windows Server 2008.vmx” 使用player启动虚拟机
vmrun -T player stop “E:\2008R2\Windows Server 2008.vmx” soft 正常关闭WS2008
vmrun -t ws listsnapshots “E:\2008R2\Windows Server 2008.vmx” 列出快照
vmrun -T ws snapshot “E:\2008R2\Windows Server 2008.vmx” fix1 创建fix1快照
vmrun -T ws deleteSnapshot “E:\2008R2\Windows Server 2008.vmx” fix1 删除fix1快照
创建克隆链接的虚拟机:将虚拟机关机,创建一个快照
vmrun -T ws clone “E:\2008R2\Windows Server 2008.vmx” E:\vm\2008R2-1.VMX linked -snapshot=fix1 -cloneName=2008R2-1

4、编写脚本

创建20个克隆链接虚拟机,并配置VNC远程端口,开启虚拟机,将下面内容复制并另存为.bat即可使用
C:
CD “C:\Program Files (x86)\VMware\VMware Workstation”
REM 为指定的虚拟机创建快照名称为fix1
vmrun -T ws snapshot “E:\2008R2\Windows Server 2008.vmx” fix1
REM 创建20个克隆链接的虚拟机
for /l %%a in (11,1,30) do (
vmrun.exe -T ws clone “E:\2008R2\Windows Server 2008.vmx” E:\VM%%a%%a.vmx linked -snapshot=fix1 -cloneName=%%a
)
REM PAUSE 克隆完成,按任意键继续

REM 启用VNC,端口%%b,密码为空
for /l %%b in (11,1,30) do (
echo answer.msg.uuid.altered = “I Copied It” >>E:\VM%%b%%b.vmx
echo RemoteDisplay.vnc.enabled = “TRUE” >>E:\VM%%b%%b.vmx
echo RemoteDisplay.vnc.port = “%%b” >>E:\VM%%b%%b.vmx
rem echo RemoteDisplay.vnc.key = “” >>E:\VM%%b%%b.vmx
)
pause 配置端口完成,按任意键继续

REM 克隆完成,间隔10秒启动虚拟机
for /l %%c in (11,1,30) do (
vmrun.exe -T ws start E:\VM%%c%%c.vmx
ping -n 10 127.0.0.1 >nul
)
pause 启动虚拟机完成,按任意键继续

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值