I have an environment where I want to change the hostname from the command line. I want to be able to script this, and since there is no vCenter in this environment, I won't be able to use powershell. I know I can use the hostname command, but that is a temporary solution, since after a reboot it changes. I have found that I can modify the /etc/sysconfig/network file to change hostnames, but I can't find a good way to script the change in a way that I could deploy the script to several different servers. Any help would be greatly appriciated.
Hey, I found the answer to this problem, so I'm posting the relevant code here:
varNewname=(Put the newname here if)
esxcfg-advcfg -s $ /Misc/HostName
perl -pi -e "s/^HOSTNAME=.*/HOSTNAME=$varNewname/g" /etc/sysconfig/network
Hope this helps someone else