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
I updated the VMware vCenter Server to 4.1 Update 1 version. But it still gives the same error,
I'm afraid I'm nearly out of ideas now.
One thing, I noticed that winNetDatacenter64Guest is still marked as experimental in the VirtualMachineGuestOsIdentifier enumeration.
Could you try the script with winNetEnterprise64Guest or winNetStandard64Guest ?
Just to make sure that it is not related to the guest OS identifier.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, I will try if I can do that with Standard version.
Hi LucD,
I created a template with Windows Server 2003 Enterprise version and tried running the script. It was running good until when it failed at 93% giving me following error:
"New-VM : 3/23/2011 11:55:06 AM New-VM The operation for the entity VirtualMachine-vm-4882 failed with the following message: "Cannot complete customization." At C:\scripts\vm.ps1:25 char:17
"
VMware tools is installed on the template.
Could it be that you have an outdated VMware Tools version in your template ?
See Cannot Complete Customization
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, I refered that post earlier. VMware tools is up to date with latest version.
I have updated my vCenter to 4.1 update 1. So, I also re-entered Administrator (and/or) a Domain Account password into the Customization Specifications file. Still the same errorm, not sure what could be the issue.
Is there anything in the vCenter logs around the time you ran the New-VM cmdlet ?
The logs are in C:\ProgramData\VMware\VMware VirtualCenter\Logs and are called vpxd-nnnn.log.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am not able to find the logs folder at that location (VirtualCenter folder) after I updated vCenter. Tried searching that vpxd log file, but couldn't find anywhere.
On what OS do you have vCenter running ? Windows 2003 ?
You can also see the logs from the vSphere client, <Home><System Logs> and select the vCenter server log.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes Windows server 2003
Yeh, found the logs from Home><System Logs. Thanks! But don't exactly understand from the logs where is the issue. Here is the latest logs I found searching keyword "errror":
I suppose just a silly question. Have you used sysprep to prepare your template?
I suspect you didn't install the sysprep files on your vCenter server for the Windows 2003 OS.
Have a look at KB1005593
Even though your template is not prepared for sysprep, the cloning process will still look for sysprep files on the vCenter server.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Dstavert for your input.
LucD, I installed sysprep files on my vCenter server as per the instructions shown in the link you gave. But it's still giving the same error "Cannot complete customization" at 93%.
One thing to notice is my vCenter folder is at a different location, don't know why. It's at C:\Documents and Settings\All Users\Application Data\VMware\VMware VirtualCenter\sysprep
I have Windows Server 2003 SP1 64-bit edition.
And I installed this sysprep file - http://www.microsoft.com/downloads/en/details.aspx?familyid=C2684C95-6864-4091-BC9A-52AEC5491AF7&dis...
You have to install the sysprep files for the OS that will run in the guest.
Your vCenter is running on a W2K3 OS, hence the different folder location.
But you are deploying a guest with W2K8, that means you need to install the sysprep files for W2K8.
In fact you should have sysprep files for all the Win OS you cna have in your guests.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
That is the sysprep process that you are seeing.
Even if you activated the VM that became the template afterwards, after the sysprep the Windows OS considers it a new installation, hance the activation.
An alternative would be to just clone an existing VM and then change the essential parts, like hostname, ip adress, adding to a domain,...
I suspect that is what Orchestrator is doing.
This way of working will get you guests with the same sysid, but it seems that this is not considered a real problem anymore.
See The Machine SID Duplication Myth
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, that is what we used to do with Orchestrator. But it was a pain and time consuming to change to change the IPs, computer name, and adding to domain for all the VMs one by one, because we use to create 100 VMs at a stretch. This script solved the issue, but it looks like it too has some of these other limitations.
Is there any other alternative to solve this issue? Thanks again!
Did you already try with a New-OSCustomization but then with the -ChangeSid:$false parameter ?
That way sysprep will not generate a new SID.
Not sure if this will help with activation though, haven't tried it yet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, in the New-OSCustomization, I have unchecked the Generate new SID paramter. This is what you meant, tight? Please see the attached screenshot,