即使在虚拟机guest os vmwaretools命令行中关闭了时间同步,当重启guestos或vmtools服务时,虚拟机仍会跟esxi同步,要彻底禁止虚拟机和esxi同步,还需在该虚拟机vmx文件中添加以下代码:
tools.syncTime = "0"
time.synchronize.continue = "0"
time.synchronize.restore = "0"
time.synchronize.resume.disk = "0"
time.synchronize.shrink = "0"
time.synchronize.tools.startup = "0"
time.synchronize.tools.enable = "0"
time.synchronize.resume.host = "0"
也可通过powercli编写脚本文件批量执行:
$vm = get-view (get-vm test-time).Id #虚机名为test-time $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec $vmConfigSpec.extraconfig = New-Object VMware.Vim.optionvalue $vmConfigSpec.extraconfig[0].Key="time.synchronize.continue" #键名 $vmConfigSpec.extraconfig[0].Value="0" #键值 $vm.ReconfigVM($vmConfigSpec)
#执行脚本后,会创建time.synchronize.continue键值,并且值为0,但是这个脚本有个缺点,就是每添加一个键值都需要重新运行一次新的脚本。
以下脚本可以一次运行,添加所有键值:
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec $spec.extraConfig = New-Object VMware.Vim.OptionValue[] (8) $spec.extraConfig[0] = New-Object VMware.Vim.optionvalue $spec.extraConfig[0].Key="tools.syncTime" $spec.extraConfig[0].Value="0" $spec.extraConfig[1] = New-Object VMware.Vim.optionvalue $spec.extraConfig[1].Key="time.synchronize.continue" $spec.extraConfig[1].Value="0" $spec.extraConfig[2] = New-Object VMware.Vim.optionvalue $spec.extraConfig[2].Key="time.synchronize.restore" $spec.extraConfig[2].Value="0" $spec.extraConfig[3] = New-Object VMware.Vim.optionvalue $spec.extraConfig[3].Key="time.synchronize.resume.disk" $spec.extraConfig[3].Value="0" $spec.extraConfig[4] = New-Object VMware.Vim.optionvalue $spec.extraConfig[4].Key="time.synchronize.shrink" $spec.extraConfig[4].Value="0" $spec.extraConfig[5] = New-Object VMware.Vim.optionvalue $spec.extraConfig[5].Key="time.synchronize.tools.startup" $spec.extraConfig[5].Value="0" $spec.extraConfig[6] = New-Object VMware.Vim.optionvalue $spec.extraConfig[6].Key="time.synchronize.tools.enable" $spec.extraConfig[6].Value="0" $spec.extraConfig[7] = New-Object VMware.Vim.optionvalue $spec.extraConfig[7].Key="time.synchronize.resume.host" $spec.extraConfig[7].Value="0" $_this = get-view (get-vm test).Id $_this.ReconfigVM_Task($spec)
# get-vm test是选择test这个VM做为对象,如果想对所有关机的VM进行修改,可以把()里的内容替换成如下两种代码的任意一种:
get-vm | where-object {$_.powerstate -eq "poweredoff"} get-vm | ? {$_.PowerState -like "poweredoff"}
本文出自 “我还活着呢” 博客,转载请与作者联系!