Link to home
Start Free TrialLog in
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
SOLUTION
Avatar of IanTh
IanTh
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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*
Avatar of papalala
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks so much, Folks!

W