Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 168400

Reset NTP Service on all hosts

$
0
0

Hi all.

 

I've been in IT for almost thirty years, and people are always telling me I should learn "language X."  They tell me it will save me time and aggrivation.  Of course, the latest is Powershell, and since I'm woriking in tVMWare infrastructure, PowerCLI just kind of follows along.  So here I sit, looking at what should be a relatively simple script, spinning my wheels wasting more ime than it would take to just do it manually in the gui!  So here I sit feeling my blood pressure rise and wonder why I bother trying this crap!  Sorry for ranting a bit, but maybe one day someone will invent a anguage that truly SIMPLIFIES THINGS!

 

My task was simple.  Change the NTP server entries on our VMWare hosts.  So I found a script in one of the forumns, and although it had "logic" (yeah right!) to restart the service after making the change, it didn't do that, so this morning, I went looking for some code to do just that last piece.  I found a script on Simon Long's blog that looked simple enough, and I could follow the logic of the commands.  So, I pasted it into a script and edited it for my environment.

 

Here's the script.

 

$Hosts= Get-VMHost

ForEach($Hostin $Hosts)

{

Remove-VmHostNtpServer-NtpServer"<old ntp server>"-VMHost$Host| Out-Null

Add-VmHostNtpServer-NtpServer"<new ntp server>"-VMHost$Host| Out-Null

Get-VmHostService-VMHost$Host| Where-Object{$_.key -eq"ntpd"} | Restart-VMHostService-Confirm:$false| Out-Null

write"NTP Server was changed on $Host"

}

 

 

Since I had already changed the host to the new address, I deleted the first two lines in the loop.  I started it off with a connect-viserver command, saved it, ran it and it bombed on the foreach loop stating that $host was read-only and couldn't be changed.  I DIDN'T ASK IT TO CHANGE IT!!!!!!  So I'm about ready to rename PowerCLI to yet another UselessPOS!  Can anyone give me som REAL logic as to why it thinks it needs to change this variable?????????????


Viewing all articles
Browse latest Browse all 168400

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>