Creating Virtual Machines with PowerCLI using a template and customizing the OS with custom data
search cancel

Creating Virtual Machines with PowerCLI using a template and customizing the OS with custom data

book

Article ID: 372734

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

To deploy multiple virtual Machine using PowerCLI avoiding manual steps and repetitive task leading to failures.

Environment

vCenter Server 8.x

Cause

Automate manual process of creating multiple Virtual Machines using a template with custom properties.

Resolution

Connect to vCenter:

PS C:\> Connect-VIServer -Server XXXXX -User xxxxx -Password xxxxx

Run the following to set variables and input parameters:

$VirtualMachinesCSV = Import-Csv -path "E:\M_VMcreation\csvfilename.csv"
foreach($VM in $VirtualMachinesCSV){
write-host $VM.Name
Get-OSCustomizationSpec -Name $VM.CustomSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UsestaticIP -IPAddress $VM.Ipaddress -Dns "xxx.xxx.xx.xx","xx.xx.xx.x" -SubnetMask "xx.xx.xx.xx" -DefaultGateway $VM.Gateway 
New-VM -Name $VM.Name -Template $VM.Template -Host $VM.DestinationHost -Datastore $VM.Datastore  -OSCustomizationSpec $VM.CustomSpec 
Set-VM -VM $VM.Name -NumCpu $VM.NumCpu -MemoryMB $VM.MemoryMB -Confirm:$false   
Get-VM -Name $VM.Name | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $VM.vPGnetwork -Type VMXNET3 -Confirm:$false
Get-VM $VM.Name | Get-NetworkAdapter | Set-NetworkAdapter -StartConnected:$true -Confirm:$false
Start-VM -VM $VM.Name -Confirm:$false -RunAsync
}

Note: InputVM.csv is sample for custom field is attached. 

Additional Information

  • Get-OSCustomizationSpec

    This cmdlet retrieves the OS customization specifications available on a vCenter Server system. To specify a server different from the default one, use the Server parameter.

  • PowerCLI Installation Guide

    PowerCLI runs on top of PowerShell, which is a cross-platform task automation and configuration management framework. It consists of a command-line shell and a scripting language.

  • Help and Support for VMware PowerCLI

    If you cannot resolve a problem with PowerCLI on your own, you can file a support request under the conditions of your VMware contract.

Attachments

InputVM.csv get_app