Message classified as External Non-Confidential
$linuxSpec = New-OSCustomizationSpec -OSType Linux -Name $VMName -DnsServer $DNS1,$DNS2 -DnsSuffix $Domain -Domain $Domain -Type Persistent -NamingScheme fixed -NamingPrefix $ServerName -Server $vcentre
# $linuxSpec = New-OSCustomizationSpec -OSType Linux -Name $VMName -Domain $Domain -DnsSuffix $Domain -Type Persistent -DnsServer $DNS1,$DNS2 -NamingScheme fixed -NamingPrefix $NetBios
write-host "CREATING NEW CUSTOMISATIONS NIC MAPPING SPECIFICATION FOR YOUR VM" -ForegroundColor Yellow
Get-OSCustomizationNicMapping $linuxSpec|Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $IP -SubnetMask $SubNetMask -DefaultGateway $Gateway -Server $vcentre
write-host "Passed point1 Get-OSCustomizationNicMapping"
New-VM -Name $VMname -Template $OS -Location $Application -VMHost $HostName -Portgroup (Get-VirtualPortGroup -Name $PortGroup -VMHost $HostName).Name -Datastore $Datastore -Server $vcentre -OSCustomizationSpec $linuxSpec -ErrorAction Stop
write-host "Passed point2 New-VM"
Start-VM $VMname |Wait-Tools -TimeoutSeconds 180
write-host "Passed point3 Start-VM "
#Check if the deploymnet is completed
$CustomisationStatus= Check-Customisation -VMname $VMName
write-host "the CustomisationStatus is $CustomisationStatus"
if ($CustomisationStatus -notlike ("SUCCESSFUL")) {
write-host "Send email the server $VMName Customisation has failed"}
#check the vm
$PingWaitCounter=[int]"0"
do {$VMReady=Check-VM-Ready-Status -vmname $vmname -IP $IP
Start-Sleep -Seconds 2
$PingWaitCounter = $PingWaitCounter +2
Write-Host "WAITING FOR SERVER TO RESPOND, NOW WAITING $PingWaitCounter" -ForegroundColor Red
} Until ((($VMReady[0] -eq "OK") -and ($VMReady[1]-eq"Success") -and ($VMReady[2] -eq "Started")) -or ($PingWaitCounter -eq "100"))
if ($PingWaitCounter -eq "100") {
Write-Host "Need to send email, the server $VMName is not responding to ping, please check the Status " -ForegroundColor Red }
#server will restart automatically one more time for the Customisation to take effect
write-host "passed this point" -ForegroundColor Yellow
do{
$VMReady=Check-VM-Ready-Status -vmname $vmname -IP $IP
Start-Sleep -Seconds 2
$WaitCounter=$WaitCounter+2
}Until ((($VMReady[0] -eq "OK") -and ($VMReady[1] -eq "Success")) -or ($WaitCounter -eq "100"))
if (($VMReady[0] -eq "OK") -and ($VMReady[1] -eq "Success") )
{write-host "The $vmname server is ready to accept commands" -ForegroundColor Green}