VMware Cloud Community
crosen
Contributor
Contributor
Jump to solution

Problem Cloning a Template

Need to create 1000 VMs based off of one template and would prefer not to do this manually. I am using the following script and it is failing. Additionally, I need to specify the resource pool, which is not in my command yet. Thanks.

Script:

$template = "acqpodad1temp"

$NewVMName ="poc1"

$datastore ="dsRTPVMware70000"

$host = "rtpvhost73"

$folder = "001.8.8.70HC.888-ACQPOC"

$rp = "001.70.888-ACQPOC"

Get-Template "$template" | New-VM -VMHost "$host" -Name "$NewVMName" -Location ( Get-Folder "$folder" ) -Datastore ( Get-Datastore "$datastore" )

Output:

Cannot overwrite variable Host because it is read-only or constant.

At C:\VMware_Healthcheck\createvms2.ps1:11 char:6

+ $host <<<< = "rtpvhost73"

Get-Folder : 3/9/2009 16:49:15 Get-Folder Folder with name '001.8.8.70HC.888-ACQPOC' not foun

cified filter(s).

At C:\VMware_Healthcheck\createvms2.ps1:15 char:92

+ Get-Template "$template" | New-VM -VMHost "$host" -Name "$NewVMName" -Location ( Get-Folder <<<< "$f

ore ( Get-Datastore "$datastore" )

New-VM : Cannot bind parameter 'Location'. Cannot convert "" to "VMware.VimAutomation.Types.Folder".

At C:\VMware_Healthcheck\createvms2.ps1:15 char:79

+ Get-Template "$template" | New-VM -VMHost "$host" -Name "$NewVMName" -Location <<<< ( Get-Folder "$f

ore ( Get-Datastore "$datastore" )

0 Kudos
1 Solution

Accepted Solutions
RobMokkink
Expert
Expert
Jump to solution

Oke that's all oke.

Can you comment out or remove the following lines:

#CREATE OBJECT CUSTOMIZATIONGUIRUNONCE

$vmcSpec.Customization.Identity.guiRunOnce = New-Object VMware.Vim.CustomizationGuiRunOnce

#GUIRUNONCE SPECIFICATION

$vmcSpec.Customization.Identity.guiRunOnce.commandList = $PostInstall

I a previous post i forgot to comment out the guirunonceobject

View solution in original post

0 Kudos
23 Replies
RobMokkink
Expert
Expert
Jump to solution

Hi Crosen,

Take a look at this document:

http://communities.vmware.com/docs/DOC-6972

crosen
Contributor
Contributor
Jump to solution

I tried that as well, but don't know what my error is....

2009-3-9 17:45:23 START AANMAKEN VIRTUAL MACHINES

2009-3-9 17:45:26 VIRTUAL MACHINE IP NIET OPGEGEVEN

2009-3-9 17:45:26 VIRTUAL MACHINE SUBNETMASK NIET OPGEGEVEN

2009-3-9 17:45:26 VIRTUAL MACHINE GATEWAY NIET OPGEGEVEN

2009-3-9 17:45:26 VIRTUAL MACHINE GATEWAY NIET OPGEGEVEN

2009-3-9 17:45:26 VIRTUAL MACHINE DNS NIET OPGEGEVEN

2009-3-9 17:45:27 DATASTORE: dsRTPVMware70000 BESTAAT

2009-3-9 17:45:28 RESOURCEPOOL: 001.70.888-ACQPOC BESTAAT NIET

2009-3-9 17:45:28 CLUSTER: 001.1.1.70HC-VT64-Rack-0,x,y BESTAAT

2009-3-9 17:45:28 CLUSTER DEFAULT RESOURCEPOOL WORDT GEBRUIKT

2009-3-9 17:45:29 FOLDER: 001.8.8.70HC.888-ACQPOC BESTAAT NIET

2009-3-9 17:45:29 DE DEFAULT FOLDER WORD GEBRUIKT

2009-3-9 17:45:29 TEMPLATE: acqpocad1temp BESTAAT

It seems to be saying that it can't find that template, but when I run the get-template command manually:

PS C:\VMware_Healthcheck\Create_VMs_Based_on_Template> get-template

Name Id

-


--

acqpocad1temp VirtualMachine-vm-2540

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Sorry the logging is in dutch.

You did not specify an ip address, subnetmask and gateway.

I will try to translate it to english when i get the change.

0 Kudos
crosen
Contributor
Contributor
Jump to solution

Is there a way to specify DHCP?

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Not at this moment. Because the script is written specific for my environment, however itś very easy to customize the clone function.

Maybe i will add it in the future.

0 Kudos
prospero63
Contributor
Contributor
Jump to solution

I am doing the same thing right now, and here are my observations on the process.

1) For whatever reason (I have an issue open with support) VMware seems to be incapable of handling more than about 5 simultaneous deployments at a time. Everything beyond that either gets put "in progress" or gets "queued"

2) For reasons I don't know (see support above) periodically deployments fail with the error "resource is not available". These occur in the middle of the deployments, for example VM 11 out of 20, so it's not like it's at the beginning or end of the process. I think it's related to how long a task sits queued up, but since tasks that have been queued longer may run after it, I'm just not sure.

3) The "sweet" spot seems to be deploying 20 or so VM's at a time, a process that takes about 2 hours in my experience. I have tried deploying from templates on NFS, iSCSI, FC and local storage to ESX hosts with NFS, iSCSI, FC and local storage. I have monitored both the network and the SAN to see if there is a bottleneck there, but from what I can tell it seems to be a limitation of VMware.

4) For whatever reason, the -datastore parameter for new-vm seems to not like iSCSI or FC based datastores, so you can't just specify it outright (i.e. I can just put the name of the local or NFS datastore in and off it goes). I could only get it to work by piping in the get-datastore cmdlet output).

Given the limitations, rather than writing a large/complex script, I have been doing the following:

new-vm -VMHost <host> -name <VMname> -Location (get-folder -name <folder> -location <datacenter>) -template <templatename> -Datastore (get-datastore -VMHost <host> -name <ds_name>) -OSCustomizationSpec <specname> -RunAsync

I'm sure there is a better way, but I haven't found it. In my case I have built scripts (essentially nothing more than a connect-viserver and 20 lines as above) to handle the deployments and do a simple find/replace for the data. I've managed to get about 200 VM's deployed in the last day. I'd have liked to done it by feeding the script the variable data out of a .CSV (or something similar) but given that (a) I'm not much of a developer and (b) I started to hit a deadline for getting VM's running as opposed to code mucked around with, I wound up going with this... so far so good (with the time caveat being the big issue, but again I think that's a VMware problem).

crosen
Contributor
Contributor
Jump to solution

Hi prospero63,

Have you been able to set the VM's hostname using the "-OSCustomizationSpec <specname>"? That is the part that I am still battling. Thanks.

0 Kudos
prospero63
Contributor
Contributor
Jump to solution

In the spec itself I used the option "use the virtual machine name". I've had no problems with that.

0 Kudos
crosen
Contributor
Contributor
Jump to solution

Back to trying to run the create-vm-csv-v16.ps1 script. I'll assign statics if I have to. It seems to hang at the following:

--- -


-


True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\VMware.Vim\1.0.0.0__10980b081e887e9f\VMware.Vim.dll

Name : rtpvcell70

Port : 443

SessionId : AC1F9D64-45D5-4663-9270-E405285F8A28

User : crosen

There were one or more problems with the server certificate:

  • A certification chain processed correctly, but terminated in a root certificate which isn't trusted

der.

  • The certificate's CN name does not match the passed value.

Name : rtpvcell70

Port : 443

SessionId : 3C19CD0D-E34D-4B43-A968-4DEB967905B4

User : crosen

Name : rtpvcell70

Port : 443

SessionId : 5923B368-3C85-47A7-8556-A88B33F1F562

User : crosen

Exception calling "CloneVM_Task" with "3" argument(s): "Not initialized: string[] commandList"

At C:\VMware_Healthcheck\Create_VMs_Based_on_Template\create-vm-csv-v16.ps1:247 char:35

+ $task = $vmmorview.CloneVM_Task( <<<< $targetview.MoRef,$vmname, $vmcSpec )

CSV file:

Naam;DataCenter;Datastore;IP;SubnetMask;Gateway;DNS;Cluster;ESXHost;ResourcePool;Folder;Template;Redeploy

"poc1;001-Americas-UK;dsRTPVMware70000;10.10.10.2;255.255.0.0;10.10.10.1;10.10.10.100;001.1.1.70HC-VT64-Rack-0,x,y;vhost1;001.8.8.70HC.888-ACQPOC;001.70.888-ACQPOC;acqpocad1temp;NO"

Log file:

2009-3-10 13:58:3 START AANMAKEN VIRTUAL MACHINES

2009-3-10 13:58:7 DATASTORE: dsRTPVMware70000 BESTAAT

2009-3-10 13:58:8 RESOURCEPOOL: 001.8.8.70HC.888-ACQPOC BESTAAT

2009-3-10 13:58:8 FOLDER: 001.70.888-ACQPOC BESTAAT

2009-3-10 13:58:9 TEMPLATE: acqpocad1temp BESTAAT

2009-3-10 13:58:14 VIRTUAL MACHINE BESTAAT NIET

2009-3-10 13:58:14 VIRTUELE MACHINE: "POC1 WORDT GEDEPLOYED

2009-3-10 13:58:22 Finished

0 Kudos
crosen
Contributor
Contributor
Jump to solution

Back to trying to run the create-vm-csv-v16.ps1 script. I'll assign statics if I have to. It seems to hang at the following:

--- -


-


True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\VMware.Vim\1.0.0.0__10980b081e887e9f\VMware.Vim.dll

Name : rtpvcell70

Port : 443

SessionId : AC1F9D64-45D5-4663-9270-E405285F8A28

User : crosen

There were one or more problems with the server certificate:

  • A certification chain processed correctly, but terminated in a root certificate which isn't trusted

der.

  • The certificate's CN name does not match the passed value.

Name : rtpvcell70

Port : 443

SessionId : 3C19CD0D-E34D-4B43-A968-4DEB967905B4

User : crosen

Name : rtpvcell70

Port : 443

SessionId : 5923B368-3C85-47A7-8556-A88B33F1F562

User : crosen

Exception calling "CloneVM_Task" with "3" argument(s): "Not initialized: string[] commandList"

At C:\VMware_Healthcheck\Create_VMs_Based_on_Template\create-vm-csv-v16.ps1:247 char:35

+ $task = $vmmorview.CloneVM_Task( <<<< $targetview.MoRef,$vmname, $vmcSpec )

CSV file:

Naam;DataCenter;Datastore;IP;SubnetMask;Gateway;DNS;Cluster;ESXHost;ResourcePool;Folder;Template;Redeploy

"poc1;001-Americas-UK;dsRTPVMware70000;10.10.10.2;255.255.0.0;10.10.10.1;10.10.10.100;001.1.1.70HC-VT64-Rack-0,x,y;vhost1;001.8.8.70HC.888-ACQPOC;001.70.888-ACQPOC;acqpocad1temp;NO"

Log file:

2009-3-10 13:58:3 START AANMAKEN VIRTUAL MACHINES

2009-3-10 13:58:7 DATASTORE: dsRTPVMware70000 BESTAAT

2009-3-10 13:58:8 RESOURCEPOOL: 001.8.8.70HC.888-ACQPOC BESTAAT

2009-3-10 13:58:8 FOLDER: 001.70.888-ACQPOC BESTAAT

2009-3-10 13:58:9 TEMPLATE: acqpocad1temp BESTAAT

2009-3-10 13:58:14 VIRTUAL MACHINE BESTAAT NIET

2009-3-10 13:58:14 VIRTUELE MACHINE: "POC1 WORDT GEDEPLOYED

2009-3-10 13:58:22 Finished

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Hi Crosen,

Comment out the following line in the script:

<br /><br/>
<br/><br/>
#GUIRUNONCE SPECIFICATION<br/><br/>
<br/><br/>
$vmcSpec.Customization.Identity.guiRunOnce.commandList = $PostInstall<br/><br/>
<br/><br/>

</p>$Postinstall is defined on top as a runonce script. We use that to join the computer to the domain, because with static ip's domain jons during depployment most of the time fails, because at that point the static ip adres gets set.

We also install SCCM agent, antivirus and some other settings, which are being refered to default when u use sysprep.

In the next release i will make sure it is variable.

0 Kudos
crosen
Contributor
Contributor
Jump to solution

Back to trying to run the create-vm-csv-v16.ps1 script. I'll assign statics if I have to. It seems to hang at the following:

--- -


-


True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\VMware.Vim\1.0.0.0__10980b081e887e9f\VMware.Vim.dll

Name : rtpvcell70

Port : 443

SessionId : AC1F9D64-45D5-4663-9270-E405285F8A28

User : crosen

There were one or more problems with the server certificate:

  • A certification chain processed correctly, but terminated in a root certificate which isn't trusted

der.

  • The certificate's CN name does not match the passed value.

Name : rtpvcell70

Port : 443

SessionId : 3C19CD0D-E34D-4B43-A968-4DEB967905B4

User : crosen

Name : rtpvcell70

Port : 443

SessionId : 5923B368-3C85-47A7-8556-A88B33F1F562

User : crosen

Exception calling "CloneVM_Task" with "3" argument(s): "Not initialized: string[] commandList"

At C:\VMware_Healthcheck\Create_VMs_Based_on_Template\create-vm-csv-v16.ps1:247 char:35

+ $task = $vmmorview.CloneVM_Task( &lt;&lt;&lt;&lt; $targetview.MoRef,$vmname, $vmcSpec )

CSV file:

Naam;DataCenter;Datastore;IP;SubnetMask;Gateway;DNS;Cluster;ESXHost;ResourcePool;Folder;Template;Redeploy

"poc1;001-Americas-UK;dsRTPVMware70000;10.10.10.2;255.255.0.0;10.10.10.1;10.10.10.100;001.1.1.70HC-VT64-Rack-0,x,y;vhost1;001.8.8.70HC.888-ACQPOC;001.70.888-ACQPOC;acqpocad1temp;NO"

Log file:

2009-3-10 13:58:3 START AANMAKEN VIRTUAL MACHINES

2009-3-10 13:58:7 DATASTORE: dsRTPVMware70000 BESTAAT

2009-3-10 13:58:8 RESOURCEPOOL: 001.8.8.70HC.888-ACQPOC BESTAAT

2009-3-10 13:58:8 FOLDER: 001.70.888-ACQPOC BESTAAT

2009-3-10 13:58:9 TEMPLATE: acqpocad1temp BESTAAT

2009-3-10 13:58:14 VIRTUAL MACHINE BESTAAT NIET

2009-3-10 13:58:14 VIRTUELE MACHINE: "POC1 WORDT GEDEPLOYED

2009-3-10 13:58:22 Finished

0 Kudos
crosen
Contributor
Contributor
Jump to solution

Back to trying to run the create-vm-csv-v16.ps1 script. I'll assign statics if I have to. It seems to hang at the following:

--- -


-


True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\VMware.Vim\1.0.0.0__10980b081e887e9f\VMware.Vim.dll

Name : rtpvcell70

Port : 443

SessionId : AC1F9D64-45D5-4663-9270-E405285F8A28

User : crosen

There were one or more problems with the server certificate:

  • A certification chain processed correctly, but terminated in a root certificate which isn't trusted

der.

  • The certificate's CN name does not match the passed value.

Name : rtpvcell70

Port : 443

SessionId : 3C19CD0D-E34D-4B43-A968-4DEB967905B4

User : crosen

Name : rtpvcell70

Port : 443

SessionId : 5923B368-3C85-47A7-8556-A88B33F1F562

User : crosen

Exception calling "CloneVM_Task" with "3" argument(s): "Not initialized: string[] commandList"

At C:\VMware_Healthcheck\Create_VMs_Based_on_Template\create-vm-csv-v16.ps1:247 char:35

+ $task = $vmmorview.CloneVM_Task( &lt;&lt;&lt;&lt; $targetview.MoRef,$vmname, $vmcSpec )

CSV file:

Naam;DataCenter;Datastore;IP;SubnetMask;Gateway;DNS;Cluster;ESXHost;ResourcePool;Folder;Template;Redeploy

"poc1;001-Americas-UK;dsRTPVMware70000;10.10.10.2;255.255.0.0;10.10.10.1;10.10.10.100;001.1.1.70HC-VT64-Rack-0,x,y;vhost1;001.8.8.70HC.888-ACQPOC;001.70.888-ACQPOC;acqpocad1temp;NO"

Log file:

2009-3-10 13:58:3 START AANMAKEN VIRTUAL MACHINES

2009-3-10 13:58:7 DATASTORE: dsRTPVMware70000 BESTAAT

2009-3-10 13:58:8 RESOURCEPOOL: 001.8.8.70HC.888-ACQPOC BESTAAT

2009-3-10 13:58:8 FOLDER: 001.70.888-ACQPOC BESTAAT

2009-3-10 13:58:9 TEMPLATE: acqpocad1temp BESTAAT

2009-3-10 13:58:14 VIRTUAL MACHINE BESTAAT NIET

2009-3-10 13:58:14 VIRTUELE MACHINE: "POC1 WORDT GEDEPLOYED

2009-3-10 13:58:22 Finished

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Did you commented out the lines i specified??

0 Kudos
crosen
Contributor
Contributor
Jump to solution

Yes, still having a problem.

#GUIRUNONCE SPECIFICATION

#$vmcSpec.Customization.Identity.guiRunOnce.commandList = $PostInstall

Exception calling "CloneVM_Task" with "3" argument(s): "Not initialized: string[] commandList"

At C:\VMware_Healthcheck\Create_VMs_Based_on_Template\create-vm-csv-v16.ps1:248 char:35

+ $task = $vmmorview.CloneVM_Task( &lt;&lt;&lt;&lt; $targetview.MoRef,$vmname, $vmcSpec )

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Can you remove the quotes in the .csv

Before "poc1 and after NO"

Put in the following lines after

#GET TEMPLATE

$vmmor = get-datacenter $datacenter | Get-Template -Name $vmtemplate

write-output $vmmor &gt;&gt; C:\error.txt

What it the content of C:\error.txt

0 Kudos
crosen
Contributor
Contributor
Jump to solution

Here...

Name Id

-


--

acqpocad1temp VirtualMachine-vm-2543

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Oke that's all oke.

Can you comment out or remove the following lines:

#CREATE OBJECT CUSTOMIZATIONGUIRUNONCE

$vmcSpec.Customization.Identity.guiRunOnce = New-Object VMware.Vim.CustomizationGuiRunOnce

#GUIRUNONCE SPECIFICATION

$vmcSpec.Customization.Identity.guiRunOnce.commandList = $PostInstall

I a previous post i forgot to comment out the guirunonceobject

0 Kudos
crosen
Contributor
Contributor
Jump to solution

SUCCESS!!!!!!!!!! Thanks so much for your help. I was also able to create a VM using DHCP by changing the following:

#CREATE OBJECT CUSTOMIZATIONFIXEDIP

#$vmcSpec.Customization.NicSettingMap[0].Adapter.Ip = New-Object VMware.Vim.CustomizationFixedIp

$vmcSpec.Customization.NicSettingMap[0].Adapter.Ip = New-Object VMware.Vim.CustomizationDhcpIpGenerator

#NETWORK SPECIFICATIONS

#$vmcSpec.Customization.NicSettingMap[0].Adapter.Ip.IpAddress = $ip

#$vmcSpec.Customization.NicSettingMap[0].Adapter.SubnetMask = $subnetmask

#$vmcSpec.Customization.NicSettingMap[0].Adapter.Gateway = $gateway

#$vmcSpec.Customization.NicSettingMap[0].Adapter.DnsServerList = $dns

0 Kudos