14 Replies Latest reply on Jan 11, 2019 9:04 AM by Schmullus

    Unable to customize cloned VM

    Schmullus Novice

      Hello,
      I have been trying to make a script to customize a VM after receiving the needed parameters as input, but I am receiving an error when I try to use the command "Set-VM" to set the customization. Here's the customization part of the script:

      $specClone = New-OSCustomizationSpec -OSCustomizationSpec $customization -Type NonPersistent $nicMapping = Get-OSCustomizationNicMapping –OSCustomizationSpec $specClone $nicMapping | Set-OSCustomizationNicMapping –IpMode UseStaticIP –IpAddress $IP –SubnetMask $subnetMask –DefaultGateway $defaultGateway –Dns $dns1, $dns2 Set-VM -VM $vm -OSCustomizationSpec $specClone

      And here's the error:

      set-vm : 1/10/2019 7:56:16 PM Set-VM
      Required property computerName is missing from data object of type CustomizationUserData
      while parsing serialized DataObject of type vim.vm.customization.UserData
      at line 1, column 947
      while parsing property "userData" of static type CustomizationUserData
      while parsing serialized DataObject of type vim.vm.customization.Sysprep
      at line 1, column 382
      while parsing property "identity" of static type CustomizationIdentitySettings
      while parsing serialized DataObject of type vim.vm.customization.Specification
      at line 1, column 257
      while parsing call information for method CheckCustomizationSpec
      at line 1, column 171
      while parsing SOAP body
      at line 1, column 64
      while parsing SOAP envelope
      at line 1, column 0
      while parsing HTTP request for method checkCustomizationSpec
      on object of type vim.VirtualMachine
      at line 1, column 0
      At line:1 char:1
      + Set-VM -VM $vm -OSCustomizationSpec $specClone
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [Set-VM], InvalidRequest
      + FullyQualifiedErrorId : Client20_VmHostServiceImpl_CustomizeVM_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVM

      Thanks in advance!

        • 1. Re:Unable to customize cloned VM
          Schmullus Novice

          Trying to fix the code part above...

          $specClone = New-OSCustomizationSpec -OSCustomizationSpec $customization -Type NonPersistent  $nicMapping = Get-OSCustomizationNicMapping –OSCustomizationSpec $specClone   $nicMapping | Set-OSCustomizationNicMapping –IpMode UseStaticIP –IpAddress $IP –SubnetMask $subnetMask –DefaultGateway $defaultGateway –Dns $dns1, $dns2  Set-VM -VM $vm -OSCustomizationSpec $specClone
          • 2. Re:Unable to customize cloned VM
            Schmullus Novice

            I give up...

            $specClone = New-OSCustomizationSpec -OSCustomizationSpec $customization -Type NonPersistent

            $nicMapping = Get-OSCustomizationNicMapping –OSCustomizationSpec $specClone 

            $nicMapping | Set-OSCustomizationNicMapping –IpMode UseStaticIP –IpAddress $IP –SubnetMask $subnetMask –DefaultGateway $defaultGateway –Dns $dns1, $dns2

            Set-VM -VM $vm -OSCustomizationSpec $specClone

            • 3. Re:Unable to customize cloned VM
              LucD Guru
              User ModeratorsCommunity WarriorsvExpert

              Did you try adding the NamingScheme parameter on the New-OsCustomizationSpec or Set-OsCustomizationSpec cmdlet.

              You have the choice of custom, fixed, prefix and vm.

              • 4. Re:Unable to customize cloned VM
                Schmullus Novice

                Hello LucD,

                thanks for the reply. I added the following to the script:

                $specClone = Set-OSCustomizationSpec -NamingScheme fixed -NamingPrefix "Teste" -OSCustomizationSpec $a[-1]


                Now I am getting another error:

                DEBUG: 1/11/2019 11:10:39 AM    Set-VM    525e0c0b-bb2b-d6c4-1602-19bd7206d6fd    
                VERBOSE: 1/11/2019 11:10:50 AM    Set-VM    Finished execution
                DEBUG: 1/11/2019 11:10:50 AM    Set-VM   
                set-vm : 1/11/2019 11:10:54 AM    Set-VM        Object reference not set to an instance of an object.    
                At line:1 char:1
                + set-vm -VM Teste -OSCustomizationSpec $specClone -Debug -Verbose
                + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    + CategoryInfo          : NotSpecified: (:) [Set-VM], ViError
                    + FullyQualifiedErrorId : Client20_ClientSideTaskImpl_ThreadProc_UnhandledException,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVM
                • 5. Re:Unable to customize cloned VM
                  LucD Guru
                  Community WarriorsUser ModeratorsvExpert

                  It looks as if the cmdlet is not happy with what you pass in the $vm variable.
                  I would need to see the complete code to further analyse.

                  • 6. Re:Unable to customize cloned VM
                    Schmullus Novice

                    I found some other post where you suggested to send the -OSCustomizationSpec parameter through the New-VM cmdlet instead of the Set-VM. It completed without error but the customization wasn't run.

                    I was using Get-VM -Name "Teste" | Set-VM -OSCustomizationSpec $specClone

                    • 7. Re:Unable to customize cloned VM
                      Schmullus Novice
                      And this is the New-VM:

                      New-VM -Name $nomeVM -VM $nomeVMClone -OSCustomizationSpec $specClone -ResourcePool $resourcePool -Location $folder -Confirm:$false

                      • 8. Re:Unable to customize cloned VM
                        Schmullus Novice

                        I changed the code and I am not getting errors now but the customization is not applying.

                        $a = Get-OSCustomizationSpec $specClone = Get-OSCustomizationSpec $a[-1] | New-OSCustomizationSpec -Name tempcust -Type NonPersistent $specClone | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP –IpAddress $enderecoIP –SubnetMask $subnetMask –DefaultGateway $defaultGateway –Dns $dns1, $dns2 New-VM -Name $vmName -VM $oldVMName -OSCustomizationSpec $specClone -ResourcePool $resourcePool -Location $folder
                        • 9. Re:Unable to customize cloned VM
                          Schmullus Novice

                          $a = Get-OSCustomizationSpec
                          $specClone = Get-OSCustomizationSpec $a[-1] | New-OSCustomizationSpec -Name tempcust -Type NonPersistent
                          $specClone | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP –IpAddress $enderecoIP –SubnetMask $subnetMask –DefaultGateway $defaultGateway –Dns $dns1, $dns2
                          New-VM -Name $vmName -VM $oldVMName -OSCustomizationSpec $specClone -ResourcePool $resourcePool -Location $folder

                          • 10. Re:Unable to customize cloned VM
                            LucD Guru
                            User ModeratorsCommunity WarriorsvExpert

                            You did start the VM?

                            The customization happens on the 1st power on.

                            • 11. Re:Unable to customize cloned VM
                              Schmullus Novice
                              Yes, but I did not wait for long. I am going to create a new VM, start it and check after a couple of hours.
                              • 12. Re:Unable to customize cloned VM
                                Schmullus Novice

                                It did not work. I changed the code to this:

                                $a = Get-OSCustomizationSpec
                                $specClone = Get-OSCustomizationSpec $a[-1] | New-OSCustomizationSpec -Name tempcust -Type NonPersistent
                                $specClone = Set-OSCustomizationSpec -NamingScheme fixed -NamingPrefix "Teste" -OSCustomizationSpec $a[-1]
                                $specClone | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP –IpAddress $enderecoIP –SubnetMask $subnetMask –DefaultGateway $defaultGateway –Dns $dns1, $dns2
                                New-VM -Name $vmName -VM $oldVMName -OSCustomizationSpec $specClone -ResourcePool $resourcePool -Location $folder | Start-VM

                                I am going to wait once more, but where can I find the logs on the customization to see what is really happening?

                                Thanks again!

                                • 13. Re:Unable to customize cloned VM
                                  Schmullus Novice
                                  So, I checked the files: toolsDeployPkg.log, guestcust.log, sysprep.xml and unattend.xml and there are no errors but the VM is not rebooting. I believe the error could be related to my attempt to clone a Windows Server 2019, so I will try with a 2016 and see if I am successfull.
                                  • 14. Re:Unable to customize cloned VM
                                    Schmullus Novice

                                    The issue was with the Windows Server 2019 as I cloned a 2016 and it worked. There is an issue with the unattend file now so I will have to sort out the customization and the parameters that are being passed to it.

                                     

                                    Thanks for the help!