You can deploy multiple virtual machines with a single network adapter and configure the deployed virtual machines to use static IP addresses by applying a customization specification.
Prerequisites
Verify that you have defined a list of static IP addresses in a CSV file.
Procedure
- Define the naming convention for the virtual machines.
$vmNameTemplate = "VM-{0:D3}"
- Save the cluster in which the virtual machines should be created into a variable.
$cluster = Get-Cluster MyCluster
- Save the template on which the virtual machines should be based into a variable.
$template = Get-Template MyTemplate
- Create the virtual machines.
$vmList = @()
for ($i = 1; $i –le 100; $i++) {
$vmName = $vmNameTemplate –f $i
$vmList += New-VM –Name $vmName –ResourcePool $cluster –Template $template
}
- Save the static IP addresses from the stored CSV file into a variable.
$staticIpList = Import-CSV C:\StaticIPs.csv
- Create the customization specification.
$linuxSpec = New-OSCustomizationSpec –Name LinuxCustomization –Domain vmware.com –DomainUsername "your_domain_username" –DomainPassword "your_domain_password" –DnsServer "192.168.0.10", "192.168.0.20" –NamingScheme VM –OSType Linux
- Clone the customization specification to a nonpersistent type.
$specClone = New-OSCustomizationSpec –Spec $linuxSpec –Type NonPersistent
- Apply the customization specification to each virtual machine.
for ($i = 0; $i –lt $vmList.Count; $i++) {
# Acquire a new static IP from the list
$ip = $staticIpList[$i].IP
# The specification has a default NIC mapping – retrieve it and update it with the static IP
$nicMapping = Get-OSCustomizationNicMapping –OSCustomizationSpec $specClone
$nicMapping | Set-OSCustomizationNicMapping –IpMode UseStaticIP –IpAddress $ip –SubnetMask "255.255.252.0" –DefaultGateway "192.168.0.1"
# Apply the customization
Set-VM –VM $vmList[$i] –OSCustomizationSpec $specClone –Confirm:$false
}