VMware Cloud Community
bgallagher72
Contributor
Contributor

Building VMs with Build script gets error on New-VM building the first one only

I have a build script to build multiple servers at a time. Only on the first VM when running the script I get this error.

New-VM : 3/5/2012 4:43:16 PM    New-VM        An item with the same key has already been added.
At C:\Users\XXXXXXXX\Documents\PowerCli\Deploy\DeployFromTemplate.ps1:67 char:10
+             New-VM <<<<  -Template $template -VMHost $vmhost -Name $vmname -Datastore $datastore `
    + CategoryInfo          : NotSpecified: (:) [New-VM], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

I do not get it on any of the other ones after that. I am wondering if this is a true error or more informational? All the VMs get build correctly using the script.

Reply
0 Kudos
6 Replies
CSIEnvironments
Enthusiast
Enthusiast

Can you please post the script in DeployFromTemplate.ps1.

Thanks!

Reply
0 Kudos
bgallagher72
Contributor
Contributor

Script attached to original post.

Reply
0 Kudos
LucD
Leadership
Leadership

Could it be that there are VMs in your CSV that already exist ?

Does this return anything ?

Import-Csv -Path '\\ltcvc02\d$\Scripts\VM_PowerCLI_Deployment\NewVMs.csv' | %{
    Get-VM -Name $_.vmname -ErrorAction SilentlyContinue
}


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

Reply
0 Kudos
bgallagher72
Contributor
Contributor

No I do not get any errors when I step throught the script in PowerGUI. Only when I build the first VM.

Reply
0 Kudos
CSIEnvironments
Enthusiast
Enthusiast

Looks like it may be a powercli issue. I've seen a few threads with this same issue. See the last post here for a fix/workaround:

http://communities.vmware.com/thread/298488?start=0&tstart=0

bgallagher72
Contributor
Contributor

From all the posts looks like a coding issue. Im not going to worry about it since it does not prevent the VMs from being built.

Reply
0 Kudos