VMware Cloud Community
NYIntensity
Contributor
Contributor

Auto cloning issue - fault.NicSettingMismatch

Hi all,

I have to create ~40 VMs, all based on  a template, so I'm giving it a go via PowerCLI.  I've had moderate success with my script, however, SOMETIMES, I get the error:

The operation for the entity VirtualMachine-vm-449 failed with the following message: "fault.NicSettingMismatch.summary"

I'm not trying to add or remove any more NICs, and the template only has one NIC. This is on vCenter Server 5, using ESXi 5 hosts. Here's my script:

Add-PSSnapin VMware.VimAutomation.Core

$creds = Get-Credential

connect-viserver vcenterserver -Credential $creds

$dns1 = "1.1.1.2"

$dns2 = "1.1.1.3"

$wins1 = "1.1.1.4"

$wins2 = "1.1.1.5"

$dnssuffix = "test.domain.org"

$servers =Import-Csv "c:\scripts\buildboxes.csv"

foreach($s in $servers){

New-OSCustomizationSpec -OSType Windows `

-fullname "Administrator" `

-orgname "Organization" `

-Name $s.name `

-ChangeSid `

-AdminPassword "Password01" `

-TimeZone "035" `

-Domain $dnssuffix `

-DomainCredentials $creds `

-autologoncount 3 `

-namingscheme Fixed `

-namingprefix $s.name

New-OSCustomizationNicMapping -OSCustomizationSpec $s.name `

-Position 1 `

-IpMode UseStaticIP `

-IPAddress $s.IPAddress `

-SubnetMask 255.255.255.0 `

-DefaultGateway 1.1.2.1`

-Dns $dns1,$dns2 `

-Wins $wins1,$wins2

new-vm -vmhost $s.vmhost -name $s.vmname -template buildbox -OSCustomizationSpec $s.name

Remove-OSCustomizationSpec $s.Name -Confirm:$false

get-vm $s.vmname | start-vm -confirm:$false -RunAsync

}

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

Note that an OSCustomizationSpec always comes with 1 NIC in there.

When you add a NIC in position 1, you end up with 2 NICs in the OSCustomizationSPec.

You can check with

Get-OSCustomizationSPec -Name YourName | Get-OSCustomizationNIcMapping

Perhaps try removing that default NIC.


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

NYIntensity
Contributor
Contributor

Thanks for that. I've tried removing "-Position 1", but that doesn't seem to help at all.

Should I instead be using the following?

Set-OSCustomizationNicMapping -OSCustomizationNicMapping $s.name

Reply
0 Kudos
LucD
Leadership
Leadership

That is 1 option, reconfigure the default OSCustomizationNicMapping.

Another option is to remove the default one (I assume it is in position 2 after your New-OSCustomizatioNicMapping cmdlet.

$nicMapping = Get-OSCustomization -Name YourName | Get-OSCustomizationNicMapping | where {$_.Position -eq 2}

Remove-OSCustomizationNicMapping -OSCustomizationNicMapping $nicMapping


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

Andr3201110141
Enthusiast
Enthusiast

I would recommend the following:

Get-OSCustomizationNicMapping $s.name | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $s.IPAddress -SubnetMask 255.255.255.0 -DefaultGateway 1.1.2.1 -Dns $dns1,$dns2

I'm a bit late, but I hope this helps.

Andre

Good design comes from intelligence.
Reply
0 Kudos
avasilsg
Contributor
Contributor

Hello Guys,

I had the same problem and solve it. You should check the missing compulsory field objects within your class. For example, I have:

VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();

...

CustomizationSpec customSpec = new CustomizationSpec();

CustomizationLinuxPrep linuxPrep = new CustomizationLinuxPrep();

..

CustomizationAdapterMapping[] customizationAdapterMapping = new CustomizationAdapterMapping[1];

If you miss the mapping, you'll finish with that error. Moreover, if you miss the compulsory IP field, the error will sill appears.

CustomizationIPSettings ip = new CustomizationIPSettings();

ip.setIp(new CustomizationDhcpIpGenerator());
Reply
0 Kudos