Hi,
How to Deploy Virtual Machines in vSphere Using PowerCLI
Virtual machine templates:
To create a template, create a new virtual machine, install the OS and configure any settings you would like to standardize with future virtual machines. Then you either clone or convert that virtual machine for a template.
Here is an example of cloning a new template called "Win7Template" from the VM "Win7VM".
C:> New-Template -VM 'Win2012VM' -Name "Server2012R2Template" -Datastore 'TestDatastore' -Location 'TestLocation'
OS Customization:
OS customization specifications are used to automate certain settings and tasks such as setting a computer's hostname and joining a computer to a domain. To create an OS specification we use the cmdlet New-OSCustomizationSpec in PowerCLI.
I created a new OS spec named "WindowsServer2012". I included the local administrator password, domain name, domain joining credentials, OS type, time zone and product key to be used. Note by default the network settings are configured for DHCP. You can set a static IP with the cmdlet New-OSCustomizationNicMapping.
C:> New-OSCustomizationSpec -Name 'WindowsServer2012' -FullName 'TestName' -OrgName 'TestOrg' -OSType Windows -ChangeSid -AdminPassword (Read-Host -AsSecureString) -Domain 'DOMAIN' -TimeZone 035 -DomainCredentials (Get-Credential) -ProductKey '1111-1111-1111-1111' -AutoLogonCount 1
Deploy a virtual machine from a template and customize settings:
Now that I have a VM template and OS customization specs, I can build a new virtual machine that will have the OS installed, be joined to a domain, set the product key and have the time zone set.
First, I place my OS Customization specs in the variable $OSSpecs.
$OSSpecs = Get-OSCustomizationSpec -Name 'WindowsServer2012'
Next, I place my VM template in a variable called $VMTemplate.
$VMTemplate = Get-Template -Name 'Server2012R2Template'
Finally, I deploy my VM with the New-VM cmdlet using my template and OS specs. I place the VM on the "VMHost-1" ESXi host and store the VM on the "TestDatastore" datastore.
New-VM -Name 'TestVM' -Template $VMTemplate -OSCustomizationSpec $OSSpec -VMHost 'VMHost-1' -Datastore 'TestDatastore
Set-OSCustomizationSpec - PowerCLI VMware.VimAutomation.Core Help Reference
Alessandro Romeo