VMware Cloud Community
Schmullus
Contributor
Contributor
Jump to solution

Unable to customize cloned VM

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!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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.


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

View solution in original post

Reply
0 Kudos
15 Replies
Schmullus
Contributor
Contributor
Jump to solution

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
Reply
0 Kudos
Schmullus
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


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

Reply
0 Kudos
Schmullus
Contributor
Contributor
Jump to solution

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
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


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

Reply
0 Kudos
Schmullus
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
Schmullus
Contributor
Contributor
Jump to solution

And this is the New-VM:

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

Reply
0 Kudos
Schmullus
Contributor
Contributor
Jump to solution

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
Reply
0 Kudos
Schmullus
Contributor
Contributor
Jump to solution

$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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You did start the VM?

The customization happens on the 1st power on.


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

Reply
0 Kudos
Schmullus
Contributor
Contributor
Jump to solution

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.
Reply
0 Kudos
Schmullus
Contributor
Contributor
Jump to solution

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!

Reply
0 Kudos
Schmullus
Contributor
Contributor
Jump to solution

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.
Reply
0 Kudos
Schmullus
Contributor
Contributor
Jump to solution

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!

Reply
0 Kudos
NelsonCandela
Enthusiast
Enthusiast
Jump to solution

Hey there!

I ran into the same problem with tons of error messages when deploying a Windows Server 2012 R2 based Template-VM with OSCustomizationSpec.

The thing is that it works flawlessly for Windows Server 2016.

I have two customization specification definitions, one for 2012 and one for 2016.

I compared those two definitions in two separate windows next to each other and they match 1:1 perfectly.

I did not use the -NamingScheme or -NamingPrefix before with Windows Server 2016.

Adding those to be able to occasionally deploy also Windows Server 2012 R2 VMs from a template added new errors that I do not understand.

$lineCount = 1

$tmpOSCust = "_tmp-OSC_" + $lineCount

$Spec = Get-OSCustomizationSpec $_.OSCustom | New-OSCustomizationSpec -Name $tmpOSCust -Type NonPersistent -NamingScheme fixed -NamingPrefix "tmp"

Hint: The variable $_.OSCustom is a value read from a .csv file and determines the customization specification name used.

The error message I get is this:

New-OSCustomizationSpec : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and

its properties do not match any of the parameters that take pipeline input.

At line:1 char:82

+ ... i-net.com | New-OSCustomizationSpec -Name $tmpOSCust -Type NonPersist ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (Win2k12R2_IP-Ad...ame_gwi-net.com:PSObject) [New-OSCustomizationSpec], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewCustomizationSpec

The above statement obviously fails, no new customization specification is being created.

Why does the template used or the server OS installed make a difference?

I think I can live with the fact that my script works fine the way it is with 2016, but as sometimes a bunch of WS2K12 VMs need to be deployed would help me save a lot of time, now that I have that all scripted.

Tanks!

BR

NC

Reply
0 Kudos