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" } )
}
Watch out with what is on the pipeline.
Better would be a full pipeline construct. Something like this
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?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Watch out with what is on the pipeline.
Better would be a full pipeline construct. Something like this
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?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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"
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
Looks like you are missing the 1st line (Get-VMHost |) or at least the pipeline symbol at the end of that line
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
My bad, I had a copy/paste error.
I corrected the code above, please try again.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great, Thank you so much for your help.
it's ok.