PowerCLI

 View Only
Expand all | Collapse all

Rename VM via PowerCLI

ronaldoalv

ronaldoalvJun 18, 2013 01:19 PM

  • 1.  Rename VM via PowerCLI

    Posted Jun 16, 2013 07:17 AM

    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



  • 2.  RE: Rename VM via PowerCLI

    Posted Jun 16, 2013 09:02 AM


  • 3.  RE: Rename VM via PowerCLI

    Posted Jun 16, 2013 11:38 AM

    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?



  • 4.  RE: Rename VM via PowerCLI

    Posted Jun 16, 2013 12:23 PM

    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



  • 5.  RE: Rename VM via PowerCLI

    Posted Jun 16, 2013 12:52 PM

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



  • 6.  RE: Rename VM via PowerCLI

    Posted Jun 16, 2013 01:11 PM

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

    why is that?



  • 7.  RE: Rename VM via PowerCLI

    Posted Jun 18, 2013 01:01 PM

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



  • 8.  RE: Rename VM via PowerCLI

    Posted Jun 18, 2013 01:10 PM

    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.



  • 9.  RE: Rename VM via PowerCLI

    Posted Jun 18, 2013 01:19 PM

    it's just wrote what I mentioned last Reply:



  • 10.  RE: Rename VM via PowerCLI

    Posted Jun 18, 2013 02:30 PM

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



  • 11.  RE: Rename VM via PowerCLI

    Posted Jun 25, 2013 10:03 AM
    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" .



  • 12.  RE: Rename VM via PowerCLI

    Posted Jun 25, 2013 10:59 AM

    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")



  • 13.  RE: Rename VM via PowerCLI

    Posted Jun 25, 2013 12:14 PM

    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?



  • 14.  RE: Rename VM via PowerCLI

    Posted Jun 25, 2013 12:43 PM

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



  • 15.  RE: Rename VM via PowerCLI

    Posted Jun 25, 2013 01:01 PM

    No clue I'm afraid



  • 16.  RE: Rename VM via PowerCLI

    Posted Jul 01, 2013 06:48 AM

    hi,

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

    did you know why?



  • 17.  RE: Rename VM via PowerCLI

    Posted Jul 01, 2013 06:55 AM

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



  • 18.  RE: Rename VM via PowerCLI

    Posted Jul 01, 2013 07:03 AM

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



  • 19.  RE: Rename VM via PowerCLI

    Posted Jul 01, 2013 07:12 AM

    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 ?



  • 20.  RE: Rename VM via PowerCLI

    Posted Jul 01, 2013 07:41 AM

    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.



  • 21.  RE: Rename VM via PowerCLI

    Posted Jul 01, 2013 08:01 AM

    Why do you add the OSCustomizationSpec parameter in 4 ?

    Afaik that is not required to rename the VM.



  • 22.  RE: Rename VM via PowerCLI

    Posted Jul 01, 2013 08:04 AM

    I added it because I want to rename also the OS Host name (the name inside the VM)



  • 23.  RE: Rename VM via PowerCLI

    Posted Jul 01, 2013 08:07 AM

    So what are you renaming in step 2 ?



  • 24.  RE: Rename VM via PowerCLI

    Posted Jul 01, 2013 08:19 AM

    I just want to rename it 2 times...



  • 25.  RE: Rename VM via PowerCLI

    Posted Jan 18, 2016 08:23 AM

    Hi,

    This just renames the VM name (display name), VMDK, vmx files name all remain same. is there any scirpt of VMware power cli?



  • 26.  RE: Rename VM via PowerCLI

    Posted Jan 18, 2016 08:38 AM

    The easiest method is by doing an svMotion, after you renamed the Displayname



  • 27.  RE: Rename VM via PowerCLI

    Posted Jan 19, 2016 06:11 AM

    incase migration is quite difficult. is somebody created a power cli script to rename entire VM (including all the files, like vmx, vmdk files)