VMware Cloud Community
ronaldoalv
Contributor
Contributor

Rename VM via PowerCLI

hi all,

I tryed to rename a VM (the host name of the VM) via PowerCLI with this code:

New-VM -Name $name -Template $template -VMHost $vmhost

Set-VM -VM $name  -OSCustomizationSpec &Spec1 -Confirm:$false

When Spec1 let the NetBIOS Name be the virtual machine name (=$name)

But, it still get the name of the template machine name (=$template),


thank's

26 Replies
a_p_
Leadership
Leadership

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

I try to do it via PowerCLI but it do nothing.

I dont know why.

do you think that I need to wait couple of minutes before it supposed to work?

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

I don't think that you have to wait. You can specify the new name using the Set-VM -Name parameter: The following works for me:

PowerCLI C:\Users\Robert> $VM = Get-VM -Name test1
PowerCLI C:\Users\Robert> $VM

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
test1                PoweredOff 1        0,250

PowerCLI C:\Users\Robert> Set-VM -VM $VM -Name test2 -Confirm:$false

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
test2                PoweredOff 1        0,250

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
ronaldoalv
Contributor
Contributor

this will change the name of the VM in vCenter GUI but, I want to rename the name of the machine inside the VM

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

Untitled.jpg

for some reasons it's take more than 15 min. and in other case it's even more.

why is that?

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

every time when I deploy VM and rename it, it take unexpected time(between 15 min. and 2 hours), why?

Reply
0 Kudos
LucD
Leadership
Leadership

When you rename the hostname in the guest OS by using the OSCustomizationSpec, you run the complete sysprep sequence.

That takes some time.

In the logs that are mentioned, you should find timestamps for the actions that are taken.

From there you should be able to determine which action(s) are the big time consumers.

Can you find anything conclusive in the logs ?

If possible, attach one of those logs.


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

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

it's just wrote what I mentioned last Reply:

Untitled.jpg

Reply
0 Kudos
LucD
Leadership
Leadership

And I was referring to the log in that message (C:\Windows\TEMP\vmware-imc\guestcustlog)


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

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

Customization in progress set to 1 at 2013-May-28 12:49:06
Rpci: Sending request='deployPkg.update.state 4 0
C:\Windows\TEMP\vmware-imc\guestcust.log'

Rpci: Sent request='deployPkg.update.state 4 0
C:\Windows\TEMP\vmware-imc\guestcust.log', reply='', len=0, status=1

Successfully opened key SYSTEM\CurrentControlSet\Control\Session Manager\
Size of reg_multi_sz 21.
Read multi_sz value from registry autocheck autochk *, size 21.
string value from registry autocheck autochk *.
Returning 1 elements
Got BootExecute from session mgr.
Native App sysprepDecrypter.exe, arguments ''
Copied file sysprepDecrypter.exe to C:\Windows\system32\sysprepDecrypter.exe
Updated boot execute value.
Successfully created/opened key SOFTWARE\VMware, Inc.\Guest Customization\
New boot execute:
autocheck autochk *
sysprepDecrypter.exe
System Drive: C:

Moving directory 'sysprep' to 'C:'

select * from win32_networkadapter where Manufacturer != 'Microsoft'
and ServiceName != 'VMnetAdapter' and  manufacturer is not null and
MACAddress is not null
Found 1 objects. Pointer 1c56c60. return code 0(0x0)
Found 0 objects. Pointer 0. return code 1(0x1)
Returning value 00:50:56:8E:6A:B4 for system property
Setting dhcp for nic # 0
Returning value \\WINTS1\ROOT\CIMV2:Win32_NetworkAdapter.DeviceID="7"
for system property
ASSOCIATORS OF {\\WINTS1\ROOT\CIMV2:Win32_NetworkAdapter.DeviceID="7"}
where ResultClass = Win32_NetworkAdapterConfiguration
Found 1 objects. Pointer 1c5ad90. return code 0(0x0)
Found 0 objects. Pointer 0. return code 1(0x1)
Clearing gateway ip addresses.
Enabling DHCP on the computer
Returning value
\\WINTS1\ROOT\CIMV2:Win32_NetworkAdapterConfiguration.Index=7 for
system property
Setting DNS Server to ip
Executing command C:\windows\system32\sysprep\sysprep.exe /quiet
/generalize /oobe /reboot /unattend:C:\sysprep\sysprep.xml

Successfully executed command C:\windows\system32\sysprep\sysprep.exe
/quiet /generalize /oobe /reboot /unattend:C:\sysprep\sysprep.xml

Trying to connect network interfaces, attempt 1
Rpci: Sending request='deployPkg.update.state 4 103
C:\Windows\TEMP\vmware-imc\guestcust.log@4000'

Rpci: Sent request='deployPkg.update.state 4 103
C:\Windows\TEMP\vmware-imc\guestcust.log@4000',
reply='queryNicsSupported', len=18, status=1

Got VMX response 'queryNicsSupported'
Rpci: Sending request='deployPkg.update.state 4 104
C:\Windows\TEMP\vmware-imc\guestcust.log@4000'

Rpci: Sent request='deployPkg.update.state 4 104
C:\Windows\TEMP\vmware-imc\guestcust.log@4000', reply='disconnected',
len=12, status=1

Got VMX response 'disconnected'
Rpci: Sending request='deployPkg.update.state 4 104
C:\Windows\TEMP\vmware-imc\guestcust.log@4000'

Rpci: Sent request='deployPkg.update.state 4 104
C:\Windows\TEMP\vmware-imc\guestcust.log@4000', reply='connected',
len=9, status=1

Got VMX response 'connected'
The network interfaces are connected on 1 second
Successfully opened key SOFTWARE\VMware, Inc.\Guest Customization\
Size of reg_multi_sz 21.
Read multi_sz value from registry autocheck autochk *, size 21.
string value from registry autocheck autochk *.
Returning 1 elements
Successfully opened key SYSTEM\CurrentControlSet\Control\Session Manager\
Size of reg_multi_sz 22.
Read multi_sz value from registry sysprepDecrypter.exe, size 22.
string value from registry sysprepDecrypter.exe.
Returning 1 elements
Going to delete file C:\Windows\system32\sysprepDecrypter.exe
Deleted file C:\Windows\system32\sysprepDecrypter.exe
Customization in progress set to 0 at 2013-May-28 13:03:19
Rpci: Sending request='deployPkg.update.state 5 0
C:\Windows\TEMP\vmware-imc\guestcust.log'

Rpci: Sent request='deployPkg.update.state 5 0
C:\Windows\TEMP\vmware-imc\guestcust.log', reply='', len=0, status=1

SysprepDecrypter has unobfuscated the password successfully
Deleting "C:\sysprep" ...
Deleted folder "C:\sysprep" .
Customization in progress set to 1 at 2013-Jun-25 13:28:07
Rpci: Sending request='deployPkg.update.state 4 0
C:\Windows\TEMP\vmware-imc\guestcust.log'

Rpci: Sent request='deployPkg.update.state 4 0
C:\Windows\TEMP\vmware-imc\guestcust.log', reply='', len=0, status=1

Successfully opened key SYSTEM\CurrentControlSet\Control\Session Manager\
Size of reg_multi_sz 21.
Read multi_sz value from registry autocheck autochk *, size 21.
string value from registry autocheck autochk *.
Returning 1 elements
Got BootExecute from session mgr.
Native App sysprepDecrypter.exe, arguments ''
Copied file sysprepDecrypter.exe to C:\Windows\system32\sysprepDecrypter.exe
Updated boot execute value.
Successfully created/opened key SOFTWARE\VMware, Inc.\Guest Customization\
New boot execute:
autocheck autochk *
sysprepDecrypter.exe
System Drive: C:

Moving directory 'sysprep' to 'C:'

select * from win32_networkadapter where Manufacturer != 'Microsoft'
and ServiceName != 'VMnetAdapter' and  manufacturer is not null and
MACAddress is not null
Found 1 objects. Pointer 1736d20. return code 0(0x0)
Found 0 objects. Pointer 0. return code 1(0x1)
Returning value 00:50:56:8E:2C:54 for system property
Setting dhcp for nic # 0
Returning value
\\TESTWINST1\ROOT\CIMV2:Win32_NetworkAdapter.DeviceID="7" for system
property
ASSOCIATORS OF {\\TESTWINST1\ROOT\CIMV2:Win32_NetworkAdapter.DeviceID="7"}
where ResultClass = Win32_NetworkAdapterConfiguration
Found 1 objects. Pointer 173ade8. return code 0(0x0)
Found 0 objects. Pointer 0. return code 1(0x1)
Clearing gateway ip addresses.
Enabling DHCP on the computer
Returning value
\\TESTWINST1\ROOT\CIMV2:Win32_NetworkAdapterConfiguration.Index=7 for
system property
Setting DNS Server to ip
Executing command C:\windows\system32\sysprep\sysprep.exe /quiet
/generalize /oobe /reboot /unattend:C:\sysprep\sysprep.xml

Successfully executed command C:\windows\system32\sysprep\sysprep.exe
/quiet /generalize /oobe /reboot /unattend:C:\sysprep\sysprep.xml

Trying to connect network interfaces, attempt 1
Rpci: Sending request='deployPkg.update.state 4 103
C:\Windows\TEMP\vmware-imc\guestcust.log@4000'

Rpci: Sent request='deployPkg.update.state 4 103
C:\Windows\TEMP\vmware-imc\guestcust.log@4000',
reply='queryNicsSupported', len=18, status=1

Got VMX response 'queryNicsSupported'
Rpci: Sending request='deployPkg.update.state 4 104
C:\Windows\TEMP\vmware-imc\guestcust.log@4000'

Rpci: Sent request='deployPkg.update.state 4 104
C:\Windows\TEMP\vmware-imc\guestcust.log@4000', reply='disconnected',
len=12, status=1

Got VMX response 'disconnected'
Rpci: Sending request='deployPkg.update.state 4 104
C:\Windows\TEMP\vmware-imc\guestcust.log@4000'

Rpci: Sent request='deployPkg.update.state 4 104
C:\Windows\TEMP\vmware-imc\guestcust.log@4000', reply='connected',
len=9, status=1

Got VMX response 'connected'
The network interfaces are connected on 1 second
Successfully opened key SOFTWARE\VMware, Inc.\Guest Customization\
Size of reg_multi_sz 21.
Read multi_sz value from registry autocheck autochk *, size 21.
string value from registry autocheck autochk *.
Returning 1 elements
Successfully opened key SYSTEM\CurrentControlSet\Control\Session Manager\
Size of reg_multi_sz 22.
Read multi_sz value from registry sysprepDecrypter.exe, size 22.
string value from registry sysprepDecrypter.exe.
Returning 1 elements
Going to delete file C:\Windows\system32\sysprepDecrypter.exe
Deleted file C:\Windows\system32\sysprepDecrypter.exe
Customization in progress set to 0 at 2013-Jun-25 13:45:02
Rpci: Sending request='deployPkg.update.state 5 0
C:\Windows\TEMP\vmware-imc\guestcust.log'

Rpci: Sent request='deployPkg.update.state 5 0
C:\Windows\TEMP\vmware-imc\guestcust.log', reply='', len=0, status=1

SysprepDecrypter has unobfuscated the password successfully
Deleting "C:\sysprep" ...
Deleted folder "C:\sysprep" .

Reply
0 Kudos
LucD
Leadership
Leadership

Why don't you try to use the Invoke-VMScript cmdlet and execute the following inside the guest OS.

$obj = Get-WmiObject Win32_ComputerSystem

$obj.Rename("NewName")


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

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

there is sometimes that the VM stop after the row : "The network interfaces are connected on 1 second"

and didn't continue to the next step.

you know why?

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

The failure reconfigured stop before the row "Successfully opened key SOFTWARE\VMware, Inc.\Guest Customization\"

Reply
0 Kudos
LucD
Leadership
Leadership

No clue I'm afraid


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

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

hi,

I found that every time that I tried to customize the VM twice, the second time failed,

did you know why?

Reply
0 Kudos
LucD
Leadership
Leadership

Did you restart the guest OS after the 1st name change ?


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

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

yes sure, you can't customize again without it... :smileyplain:

Reply
0 Kudos
LucD
Leadership
Leadership

So you are doing the rename with the OSCustomizationSpec  ?

If yes, you might have hit the problem described in KB929828

What failure do you get ? Any error messages ? Anything in the log ?


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

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

1. I deploy a VM via PowerCLI

2. I run OSCustomizationSpec via PowerCLI and it's really change the name inside the VM

3.  I turn off the VM.

4. I run this line: "Set-VM -VM VMOldName -Name VMNewName -OSCustomizationSpec Spec1" that change the name of the VM (not inside) and after it run the OSCustomizationSpec again.

5. the neme is not change never because the customization is not finished never, it stack when the last rows in the log file is :

Got VMX response 'connected'

The network interfaces are connected on 1 second

the next rows (that didn't appear but i know that from the first customization) is:

Successfully opened key SOFTWARE\VMware, Inc.\Guest Customization\

Size of reg_multi_sz 21.

thanks again.

Reply
0 Kudos