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:
Thanks in advance!
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
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
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
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
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:
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
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
New-VM -Name $nomeVM -VM $nomeVMClone -OSCustomizationSpec $specClone -ResourcePool $resourcePool -Location $folder -Confirm:$false
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$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
You did start the VM?
The customization happens on the 1st power on.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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!
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!
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