VMware Cloud Community
Kiala
Contributor
Contributor
Jump to solution

Auto Deploy Multiple VMs Script Error

Hi Guys,

I am trying to create multiple VMs with unique IP address and NetBIOS name for each VMs thrugh a Powershell script. Here is my scenario:

I have 2 VMs on one of my server x.x.x.x


1. Autodeploy-1 – The VM on which I am running the script through vSphere PowerCLI
2. AutoDeployVM – Template I am using for creating other VMs.

#Script

# Virtual Center Details

$server_address = “x.x.x.x”
$username = “xxx”
$password = “xxxxxx”

# Vm Details
$destination_host = “x.x.x.x”
$template_name = “AutodeployVM”
$datastore_name = “dataStore1 (9)”

$customization = "customfile"

# Name the VMs in this array
$array = “VPS-Test1″,”VPS-Test2″
$iparray = “x.x.x.1″, “x.x.x.2″
$a= 0

Connect-VIServer -Server $server_address -Protocol https -User $username -Password $password

foreach ($vm in $array)
{

Get-OSCustomizationSpec $customization | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $IParray[$a] -SubnetMask z.z.0.0 -DefaultGateway y.y.y.y -Dns x.x.x.35,x.x.x.36

$vm=New-VM -Name $vm -Template $template_name -Host $destination_host -Datastore  $datastore_name -OSCustomizationSpec $customization

-Confirm:$false $a = $a + 1

}

I have placed the customization file (customfile) in the same folder where the script is. Below is the content of my customfile:

New-OSCustomizationSpec -Name Spec -OSType Windows -FullName Administrator -AdminPassword ****** -Domain abcd.com -DomainUsername abc -DomainPassword ********

I am getting following errors:

1. Set-OSCustomizationSpec : A parameter cannot be found that matches parameter name 'IpMode'.

2. New-VM        Could not find Template with name 'AutodeployVM'.

3. New-VM        Template parameter: Could not find any of the objects specified by name.

Can you guys help me with this. Am I missing anything. I am very new to this thing. Appreciate your help.

Thanks,

Kiala

0 Kudos
63 Replies
gudhillo
Contributor
Contributor
Jump to solution

Hi LucD,

Actually I did not understood you righly, not sure what you meant by that , as New-VM is deploing the VM along with OS, once job starts, it deploy vm and Os deployment also starts from the mention template in the script. if we have set "$MaxRunning" = 2, deployment of VM along with OS deployment should not start more than 2. But this doesnt work, script start deployment of vm which is mention in $HOW_MANY_TO_CREATE=3 and not as mention in $MaxRunning.

Regards

Gurjit Dhillon

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik, the New-VM creates the VM and with the Start-VM the actual OS sysprep will start.

The Start-VM returns immediatly after the VM is powered on.

The end of the sysprep needs to be discovered in a different way.

You could for example 'ping' the VM to see if it is up and running.


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

0 Kudos
gudhillo
Contributor
Contributor
Jump to solution

Hi LucD,

Sorry to bother you again, asking the same question as its not working for me with you script you have provided , is it possible to run 3 concurrent deployment from the script, and other should wait in queue till any of them has been completed ?

Regards

Gurjit Dhillon

0 Kudos
realkeny
Contributor
Contributor
Jump to solution

I know this issue is already resolved, but i was just searching the community for some solutions when i came across this. I was also trying to automate the deployment of VMs using a single template when i stumble into creating VMs using an XML file on one of the VMware community documentation on using the PowerCLI. But the solution was too brief that i could not do much with it, but it offered me some insight into how one could actually automate the cloning of a VM template to create multiple VMs with each VM having its own predefined custom settings such as Hard drives, Memory, networking setttings etc. I have attached the script file that i developed to do this and also an xml file that contain the template for specifying the settings for each VM. I do hope someone in the community will find it useful.

0 Kudos