Avatar of williamwlk
williamwlk
 asked on

How to chang hostname of VM via PowerCLI

I'd like to change hostname of VM via PowerCLI

VSphere 4/5

I found this :

Get-VM | `
Where-Object { $_.Guest.HostName } | `
ForEach-Object { Set-VM -VM $_ -Name $_.Guest.HostName -Confirm:$false }

Open in new window


http://communities.vmware.com/message/1737030?tstart=0

But I do not properly understand Where-Object and $_.Guest.Hostname properties.

VMTools installed in VM.

Help,  Folks.

Appreciate it.

W
VMwareVirtualization

Avatar of undefined
Last Comment
williamwlk

8/22/2022 - Mon
SOLUTION
IanTh

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
IanTh

if you change the name of the vm see

Generating new certificates for the ESX host
 
The ESX host generates certificates the first time the system is started. Under certain circumstances, it might be required to force the host to generate new certificates. Typically new certificates only need to be generated if the hostname has been changed or the certificates have been deleted accidentally.
 
Each time you restart the vmware-hostd process, the mgmt-vmware script searches for existing certificate files ( rui.crt and rui.key). If the files cannot be found, new certificate files are generated.
 
To generate new certificates:
 1.Put the host into Maintenance Mode.
2.In the directory /etc/vmware/ssl, back up any existing certificates by renaming them with these commands:

[root@server root]# mv /etc/vmware/ssl/rui.crt /etc/vmware/ssl/orig.rui.crt
[root@server root]# mv /etc/vmware/ssl/rui.key /etc/vmware/ssl/orig.rui.key

Note: If you are regenerating certificates because you accidentally deleted them, you do not have to rename them.

 
3.Reboot your host to allow it to begin using the new certificate, or restart the host services:

 a.Restart hostd, using this command:

service mgmt-vmware restart

 
b.Restart vmkauthd, using this command:

service vmware-vmkauthd restart


 
4.Exit Maintenance Mode.
5.Confirm that the ESX host successfully generated new certificates by running this command and comparing the time stamps of the new certificate files with orig.rui.crt and orig.rui.key:

[root@server root]# ls -la /etc/vmware/ssl/rui*
papalala

Mentioned script changes name of the machine to its hostname.

If you want to change hostname of the machine try to use Invoke-VMScript with wmic:

wmic computersystem where name=`"%computername%`" call rename name=`"$VM`"
SOLUTION
papalala

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
williamwlk

ASKER
Thanks Folks,

Papalala, mine is Linux VM.

So,  i need to do the following changes :

[root@rhel6 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=rhel6.tester.pro

[root@rhel6 ~]# hostname
rhel6.tester.pro

[root@rhel6 ~]# cat /etc/hosts
10.200.20.55 rhel6.tester.pro
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.10 rhel6.tester.pro rhel6
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
williamwlk

ASKER
Thanks so much, Folks!

W