Automation

 View Only
  • 1.  plan a task to restart a service like ntpd on all esx in vcenter

    Posted Apr 07, 2020 02:38 PM

    Hi,

    i think the title is preaty clear. We have a vcenter versin 6.7 with multiple host on esxi server 6.7.0.

    i would like to plan a task to restart a service like ntp on all esx in this vcenter,

    i have this script, is it ggod for you ?

    Connect-viserver vcenter1 -user vcenter -pass password

    foreach($esx in Get-VMHost){   

    Restart-VMHostService -HostService ( $_ | Get-VMHostService | Where { $_.Key -eq "ntpd" } )

    }



  • 2.  RE: plan a task to restart a service like ntpd on all esx in vcenter
    Best Answer

    Posted Apr 07, 2020 02:45 PM

    Watch out with what is on the pipeline.
    Better would be a full pipeline construct. Something like this

    Connect-viserver vcenter1 -user vcenter -pass password

    Get-VMHost |

    Get-VMHostService | where{$_.Key -eq 'ntpd'} |

    Restart-VMHostService -Confirm:$false


    But what do you mean by "plan a task to restart"?

    Would this be a scheduled task?



  • 3.  RE: plan a task to restart a service like ntpd on all esx in vcenter

    Posted Apr 07, 2020 03:49 PM

    from time to time some of the vcenter's esx do not have their clock up to date, so the vms too. simply restarting the service resets the clock. it usually happens at every time change (summer / winter)

    so i would have a scheduled task to plan this script.

    thank you for your answers . i'm going to try it



  • 4.  RE: plan a task to restart a service like ntpd on all esx in vcenter

    Posted Apr 08, 2020 07:38 PM

    Hi , itry this script but i have this error



  • 5.  RE: plan a task to restart a service like ntpd on all esx in vcenter

    Posted Apr 08, 2020 07:48 PM

    Looks like you are missing the 1st line (Get-VMHost |) or at least the pipeline symbol at the end of that line



  • 6.  RE: plan a task to restart a service like ntpd on all esx in vcenter

    Posted Apr 10, 2020 07:01 AM

    Hi,

    its not missing the pipeline look, when i just run all in one line i have the same error,

    and when i run just the line Get-VMHost with the pipeline it's missing anythink

    look the attached screen

    than you for your help



  • 7.  RE: plan a task to restart a service like ntpd on all esx in vcenter

    Posted Apr 10, 2020 07:07 AM

    My bad, I had a copy/paste error.
    I corrected the code above, please try again.



  • 8.  RE: plan a task to restart a service like ntpd on all esx in vcenter

    Posted Apr 10, 2020 07:20 AM

    Great, Thank you so much for your help.

    it's ok.



  • 9.  RE: plan a task to restart a service like ntpd on all esx in vcenter

    Posted Apr 07, 2020 03:27 PM

    1. To check status of NTP services on all Hosts :-

    Get-VMHost | Select Name, @{N="NTPServer";E={$_ | Get-VMHostNtpServer}}, @{N="ServiceRunning";E={(Get-VmHostService -VMH

    ost $_ | Where-Object {$_.key -eq "ntpd"}).Running}}

    2.To Configure NTP Server, Config Policy & Start it, run below:-

    Get-VMHost | Add-VMHostNtpServer PUTNTPServerIPs

    Get-VMHost | Get-VMHostFirewallException | where {$_.Name -eq "NTP client"} | Set-VMHostFirewallException -Enabled:$true

    Get-VMHost | Get-VmHostService | Where-Object {$_.key -eq "ntpd"} | Start-VMHostService

    Get-VMhost | Get-VmHostService | Where-Object {$_.key -eq "ntpd"} | Set-VMHostService -policy "automatic"