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:
The vCenter that doesn't work (task created multiple times):
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
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
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.
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
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
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
It's basically just displaying all the error as the vm already exist. Maybe this was a build related bug?
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
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
Duplicate Tasks
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.
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