VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

starting ntp on esxi_powercli

hi Luc,

can you check if this is the corrrect way of starting ntp service

$clu=read-host "provide cluster name"

$cluster=Get-Cluster -Name $clu

$vmhosts=get-vmhost -Location $cluster

foreach($vmhost in $vmhosts)

{

$ntpd=Get-VMHostService -VMHost $vmhost|?{$_.Key -eq 'ntpd'}

$ntpd.Running

if($ntpd.Running -eq 'false')

{

$ntpd|Start-VMHostService -WhatIf

}

}

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Yes, that will work, but I would be tempted to do it in more 'PowerShell' kind of way.

$clu = read-host "provide cluster name"

Get-Cluster -Name $clu |

   Get-VMHost |

   Get-VMHostService |

   where {$_.Key -eq 'ntpd' -and -not $_.Running} |

   Start-VMHostService -Confirm:$false -WhatIf


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Yes, that will work, but I would be tempted to do it in more 'PowerShell' kind of way.

$clu = read-host "provide cluster name"

Get-Cluster -Name $clu |

   Get-VMHost |

   Get-VMHostService |

   where {$_.Key -eq 'ntpd' -and -not $_.Running} |

   Start-VMHostService -Confirm:$false -WhatIf


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaks Luc it is working .and it is more poweshellish way using pipelines.

0 Kudos