opariffazman
Contributor
Contributor

Task being created multiple times.

Hi there,

I was creating a simple script to Clone VM from .csv list. It was working well on certain vCenter, however, when tried on different vCenter, the task was created multiple time resulting in an error saying that the vm already exist, I'm not sure why this happens on this server specifically.

Attached is the script used. And some additional details.

 

The vCenter version that works is:

  • Version 6.5.0
  • Build 8024368

 

The vCenter that doesn't work (task created multiple times):

  • Version 6.5.0
  • Build 5973321
0 Kudos
13 Replies
LucD
Leadership
Leadership

You have several Write-Host lines in the script.

It would help if you can provide a sample short CSV file and the output you see in the console.


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

0 Kudos
opariffazman
Contributor
Contributor

Does the Write-Host affect the script at all? Because the script can run as intended on the other version of vCenter. Attached is the screenshot as per requested.

0 Kudos
LucD
Leadership
Leadership

No, the Write-Host lines should have no impact on teh functioning of the New-VM cmdlet.

Btw, are you sure there are no unregistered VMs already on the datastore you are targetting?
Can you check with the File Browser in the web client?


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

0 Kudos
opariffazman
Contributor
Contributor

Yes, I'm 100% sure. It actually happens like this, when you try to clone a new VM, what the vCenter did is, it try to execute the New-VM cmd 3 times, the first one being the supposed behavior, but the other 2 being a duplicate of the first task, so that's why the error "Name already exist". The thing is, when tried on other build of the vCenter, it works perfectly fine.

0 Kudos
LucD
Leadership
Leadership

Another possibility could be multiple connections to the same vCenter.
You could also place this line in the script before you do the Connect-VIServer

Disconnect-VIServer * -force:$true -Confirm:$false

From your screenshot I can't deduce if the VM loop runs through completely before it starts the 2nd and 3th one.
I mean do you see all Write-Host lines for the creation of the 1st VM before the 2nd starts?


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

0 Kudos
opariffazman
Contributor
Contributor

I believe that can be a possibility too. However, the scripts does loop accordingly, for the next other task when configuring vRAM, vCPU etc. It only execute the first New-VM command weirdly. Here's another screenshot(It's actually running live right now).

0 Kudos
LucD
Leadership
Leadership

That looks as if the New-VM is executed 3 times in a row.
Did you already try removing the Out-Null, so we can see any eventual output.
And perhaps add the Verbose switch on the New-VM cmdlet.

Is there any further information in the Tasks and Events on the vCenter?


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

0 Kudos
opariffazman
Contributor
Contributor

Yep, that's why I can't figure this out, the same error appear even without the Out-Null, and may I know what you mean by adding verbose switch? I've also tried adding -WhatIf to see how it goes, turns out it loops perfectly fine without the repetition. Here's a screenshot of the output.

0 Kudos
LucD
Leadership
Leadership

I meant adding the parameter -Verbose on the New-VM cmdlet.

That output with the WhatIf is interesting.

That proves that there is apparently nothing wrong with the logic of the script.

That could mean that the vCenter/ESXi node, for one reason or another, starts/restarts the cloning of the VM a number of times.

Is there anything in the Related Events frame under Task and Events - Tasks when you select the task that corresponds with the New-VM?


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

0 Kudos
opariffazman
Contributor
Contributor

It's basically just displaying all the error as the vm already exist. Maybe this was a build related bug?

0 Kudos
LucD
Leadership
Leadership

The Related Events on the VM cloning Task doesn't show anything?

And what versions are you experiencing this with?

vSPhere, PowerCLI and PowerShell?

Write-Host "vCenter: $($global:DefaultVIServer.Version).$($global:DefaultVIServer.Build)"

Write-Host "ESXi: $((Get-VMHost | %{""$($_.Version).$($_.Build)""} | Sort-Object -Unique)  -join '|')"

Write-Host "PowerCLI: $((Get-Module vmware.powercli -ListAvailable).Version)"

Write-Host "PowerShell: $($PSVersionTable.PSVersion)"


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

0 Kudos
opariffazman
Contributor
Contributor

Sorry for late reply, just got back from the holidays, I tried the script once again, and here's what I found on the Task & Related Events.

Actual Task

task1.png

Duplicate Tasks

task1_dup.png

task1_dup1.png

And regarding the version. Here it is:

vCenter: 6.5.0.5973321

ESXi: 6.0.0.3620759|6.5.0.6765664|6.5.0.7967591|6.5.0.9298722

PowerCLI: 11.0.0.10380590

PowerShell: 5.1.16299.666

Thanks LucD in advance.

0 Kudos
LucD
Leadership
Leadership

I'm afraid I don't have an explanation at the moment.

One more thing you could check (and share), is the vpxd log (via Web Client - Monitor - System Logs).

There might be some clues in there.


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

0 Kudos