I always found with the custom specs that i needed to have a second NIC card in my initial template that i was cloning from This is what i have used successfully - Its pretty specific to my e...
See more...
I always found with the custom specs that i needed to have a second NIC card in my initial template that i was cloning from This is what i have used successfully - Its pretty specific to my environment but i think you will get the idea.
param(
$staging_vcenter = '192.168.101.101',
$OrgName = "test",
$VMPassword = "pass",
##### AMP Hosts #####
$Esxihost = 'esx01.build.local',
$VMVER = 'v9',
##### Management #####
$MGMT='MGMT_VLAN',
$MGMTVLAN='105',
$VMSubnet ="255.255.255.0",
$VMDefaultGateway ="192.168.105.1",
##### Customisation Specs #####
$OSCostumSpec_VC = "VC-Vcenter",
##### VM Templates #####
$vcenterTemplate = 'W2K12R2-STD-Template',
##### VM IP Addressing #####
$VCVMIP ="192.168.105.100",
##### VM Hostnames #####
$VCVM ="vc.domain.local",
##### VM License Keys #####
$WinProductKey_VC = "12345-12345-12345-12345-12345",
##### Domain, DNS, Timezone #####
$domainName = "build.local",
$DNS = "192.168.101.253",
$DNS2 = "192.168.101.252",
$TimeZone = "090"
)
#End Setting Paramters for Scripts
#Connect to vCenter
Write-Verbose "Connecting to vCenter"
$server = Connect-VIServer $vCenter -credential $(get-credential)
$myhost = Get-VMHost -Name $Esxihost
$h1ds1 = $myhost | Get-Datastore -name *local
New-OSCustomizationSpec -Name $OSCostumSpec_VC -OSType Windows -AdminPassword $VMPassword -TimeZone $TimeZone -ProductKey $WinProductKey_VC -ChangeSid -OrgName $OrgName -NamingScheme Fixed -NamingPrefix $VCVM.split(".")[0] -fullname Administrator -Workgroup WORKGROUP
New-OSCustomizationNicMapping -OSCustomizationSpec $OSCostumSpec_VC -IpMode UseStaticIP -IPAddress $VCVMIP -SubnetMask $VMSubnet -DefaultGateway $VMGefaultGateway -Dns $DNS,$DNS2 -Position 1
New-VM -VMHost $Esxihost -Name $VCVM -Datastore $h1ds1 -Template $vcenterTemplate -OSCustomizationSpec $OSCostumSpec_VC
Get-VM -name $VCVM | Set-VM -Version $VMVER -confirm:$false
Get-NetworkAdapter -VM $VCVM | where {$_.Name -eq "Network adapter 2"} | Remove-NetworkAdapter -confirm:$false
Get-NetworkAdapter -VM $VCVM | where {$_.Name -eq "Network adapter 1"} | Set-NetworkAdapter -NetworkName $MGMT -confirm:$false -StartConnected:$true
Remove-OSCustomizationSpec $OSCostumSpec_VC -confirm:$false
Set-VM -VM $VCVM -MemoryGB 24 -NumCpu 4 -Description "vCenter Server" -confirm:$false
$VMdisk = Get-HardDisk -vm $VCVM -Name "Hard Disk 1"
Set-HardDisk -HardDisk $VMdisk -CapacityGB 60 -confirm:$false
$VMdisk2 = Get-HardDisk -vm $VCVM -Name "Hard Disk 2"
Set-HardDisk -HardDisk $VMdisk2 -CapacityGB 40 -confirm:$false