PowerCLI

 View Only
  • 1.  Get VMs that sync time with host

    Posted Apr 29, 2019 10:51 AM

    Hello,

    I need to Get VMs that sync time with host, and also disable this feature to force VMs to sync against the configured NTP server on the OS level.

    Thank you,



  • 2.  RE: Get VMs that sync time with host
    Best Answer

    Posted Apr 29, 2019 02:51 PM

    To disable that you can do

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $spec.tools = New-Object VMWare.Vim.ToolsConfigInfo

    $spec.tools.syncTimeWithHost = $false


    Get-VM |

    where{$_.ExtensionData.Config.Tools.syncTimeWithHost} |

    ForEach-Object -Process {

       $_.ExtensionData.ReconfigVM($spec)

    }

    To set the NTP configuration inside your guest OS, depends on which guest OS you are running.

    You can do that part via Invoke-VMScript



  • 3.  RE: Get VMs that sync time with host

    Posted Jul 11, 2022 05:11 AM

    Hi. I can't run this command in powercli. how can run for all vm in vcenter in powercli. 



  • 4.  RE: Get VMs that sync time with host

    Posted Jul 11, 2022 06:13 AM

    That "I can't run this command" is a bit vague I'm afraid.



  • 5.  RE: Get VMs that sync time with host

    Posted Jul 06, 2023 06:56 AM

    Hi ,

     

    How can i import a Csv file to disable the time sync setting with host for some specific VMs.

    Please can you help me.

     

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $spec.tools = New-Object VMWare.Vim.ToolsConfigInfo

    $spec.tools.syncTimeWithHost = $false


    Get-VM |

    where{$_.ExtensionData.Config.Tools.syncTimeWithHost} |

    ForEach-Object -Process {

       $_.ExtensionData.ReconfigVM($spec)

    }



  • 6.  RE: Get VMs that sync time with host

    Posted Jul 06, 2023 07:07 AM

    Assuming you have a CSV with a column named Name, you could do

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $spec.tools = New-Object VMWare.Vim.ToolsConfigInfo
    $spec.tools.syncTimeWithHost = $false
    
    $vms = Import-Csv -Path .\vms.csv -UseCulture
    Get-VM -Name $vms.Name |
    where{$_.ExtensionData.Config.Tools.syncTimeWithHost} |
    ForEach-Object -Process {
       $_.ExtensionData.ReconfigVM($spec)
    }