VMware Cloud Community
pargit
Enthusiast
Enthusiast

New-VM create two separate processes and fail

Hi,

i have a strange problem with my deploy vm script.

i have several clusters in the same VC, in different locations (different storage, networks etc..)

i trigger the new-vm as such:

$datastore = "Ram_DS_Cluster"

$cluster = "UCS-Ramle-Cluster"

$vcserver = "pv-vcenter-01.xxx"

$vmhost = Get-Cluster $cluster|Get-VMHost |where {$_.ConnectionState -eq "Connected"}| Sort MemoryUsageGB |Select Name,@{Expression={[math]::round($_.MemoryUsageGB)}}|Select -First 1

$tempSpec = Get-OSCustomizationSpec -Name "windows_config_ramle" -Server $vcserver| New-OSCustomizationSpec -Name "mom2o" -Type NonPersistent

$nicmapping = Get-OSCustomizationNicMapping -OSCustomizationSpec $tempSpec

$nicmapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IPAddress "10.10.10.10" -SubnetMask "255.255.255.0" -Dns "10.20.30.40" -DefaultGateway "10.10.10.1"

New-VM -Name "test-2016" -Server $vcserver -VMHost $vmhost.Name -Location "New servers Ramle" -Datastore $datastore -Notes "bla" -VM "Win2016_template_ramle" -OSCustomizationSpec $tempSpec -RunAsync -EA SilentlyContinue

on most of the clusters i get the command to run successfully but on one of them i see this behavior:

PS M:\> New-VM -Name "test-2016" -Server $vcserver -VMHost $vmhost.Name -Location "New servers Ramle" -Datastore $datastore -Notes "bla" -VM "Win2016_template_ramle" -OSCustomizationSpec $tempSpec -RunAsync -EA SilentlyContinue

Name                           State      % Complete Start Time   Finish Time

----                           -----      ---------- ----------   -----------

ApplyStorageDrsRecommendati... Running             0 10:26:44 AM             

ApplyStorageDrsRecommendati... Running             0 10:26:49 AM        

The first task start directly in 27%, and the second follow up few seconds later and fail on "Vm already exist"

and if remove the -EA..

PS M:\> New-VM -Name "test-2016" -Server $vcserver -VMHost $vmhost.Name -Location "New servers Ramle" -Datastore $datastore -Notes "bla" -VM "Win2016_template_ramle" -OSCustomizationSpec $tempSpec

New-VM : 2/28/2018 10:45:14 AM    New-VM        The operation for the entity "Ram_DS_Cluster" failed with the following message: "The name 'test-2016' already exists."   

At line:1 char:1

+ New-VM -Name "test-2016" -Server $vcserver -VMHost $vmhost.Name -Location "New s ...

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

    + CategoryInfo          : NotSpecified: (:) [New-VM], DuplicateName

    + FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

i can't figure out what has changed since it worked like a charm for over a year.

I tried using the following versions of PCLI:

VMware vSphere PowerCLI 5.5 Release 2 Patch 1 build 1931983

VMware PowerCLI 6.5 Release 1 build 4624819

both react the same.

can someone can direct me to what i need to check ?

thanks

Mordechai

0 Kudos
23 Replies
pargit
Enthusiast
Enthusiast

i did that, but the first task create the folder and the second fail with this error.

0 Kudos
LucD
Leadership
Leadership

Looks like there might be something fishy with that template then.

More so since other templates seem to work ok as you said earlier.


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

0 Kudos
pargit
Enthusiast
Enthusiast

so, i found the problem .

one of my colleges cloned the templates to another data center (in the same vc) and forgot to change the names.

so i tried to create new-vm from one DC to another and that's why it failed.

i can't tell how i missed that but i appreciate the help and ideas.

thanks

Mordehcai

0 Kudos
LucD
Leadership
Leadership

Good you found the solution :smileycool:


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

0 Kudos