$vcenter= “vcenter.domainname.com”
$esxserver = “server1.domainname.com”
$hostname = “server1”
$cluster = “your cluster name here”
$vmotip = “99.99.99.999”
$vmotsub = “255.255.255.0”
$vmotvlan = “99”

##Connect to vCenter server
#
Connect-Viserver $vcenter

##Add the new ESX host to the Cluster specified above
#
Add-VMHost -Name $esxserver -Force -Location ( Get-Cluster $cluster )

##Pause Script for admin to place ESX server into Maintenance Mode
#
Write-Host “Connect to the vcenter server and place the ESX server $esxserver in Maintenance mode”
Write-Host “Once in the host is in Maintenance mode, press any key to continue”
$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)

$hst = get-vmhost $esxserver

if ($hst.connectionstate -eq “Maintenance”) {
$hst | New-VirtualSwitch -name vSwitch1 -numports 256

##Remove Default VM Portgroup on vSwitch0
#
$hst | Get-VirtualSwitch -name vSwitch0 | Get-VirtualPortGroup -name “VM Network” | Remove-VirtualPortGroup -confirm:$False

##Configure vMotion IP / PortGroup
#
New-VMHostNetworkAdapter -VMHost $hst.name -PortGroup “vMotion” -VirtualSwitch vSwitch0 -IP $vmotip -SubnetMask $vmotsub -VMotionEnabled $true;
$hst | Get-VirtualPortGroup -Name vMotion | Set-VirtualPortGroup -VLanId $vmotvlan

##Set vSwitch0 / PortGroup Nic Policies
#
######################################
## Update NIC Teaming Order ##
######################################
$hst | Get-VirtualSwitch -name vSwitch0 | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic0,vmnic6
$hst | Get-VirtualPortGroup -name vMotion | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic0 -MakeNicActive vmnic6
$hst | Get-VirtualPortGroup -name “Management Network” | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic6 -MakeNicActive vmnic0

##Configure Guest vSwitch1
#
######################################
## Update NICs Used ##
######################################
$switch = $hst | Get-VirtualSwitch -name vSwitch1
get-virtualswitch -vmhost $hst.name -name vswitch1 | Set-VirtualSwitch -Nic vmnic1,vmnic7 -confirm:$false
$switch | New-VirtualPortGroup -name vLAN0998_999.999.98.X -vlanid 98
$switch | New-VirtualPortGroup -name vLAN0999_999.999.99.X -vlanid 99

##Rename Local Datastore to “ – Local Storage”
#
Get-VMHost $hst | get-datastore | Set-Datastore -Name “$hostname – Local Storage”

##Configure NTP Settings and start the service
#
Add-VMHostNtpServer -NtpServer “ntpserver.domainname.com” -vmhost $hst
$hst | Get-VMHostService | where {$_.Key -eq “ntpd”} | Set-VMHostService -Policy “on” | Restart-vmhostservice -confirm:$false

##Configure Domain Name and DNS Servers
#
$hst | get-vmhostnetwork | Set-VMHostNetwork -hostname $hostname -domainname domainname.com -dnsaddress ““, “” -searchdomain “domainname.com”

##Pause Script for admin to run VMA commands, e.g. Install Dell OMSA from VMA
#
Write-Host ‘Please login to the VMA and run the following commands:’
Write-Host “vifp addserver $esxserver”
Write-Host “vifptarget -s $esxserver”
Write-Host ‘/home/vi-admin/New-Dell-Esx-Install.sh –install’
Write-Host ‘Once complete, press any key to continue…’
$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)

##Disable SSH
#
Get-VMHostService -VMHost $hst.name | where {$_.Key -eq “TSM-SSH”} | Stop-VMHostService
$hst | Get-VMHostService | where {$_.Key -eq “TSM-SSH”} | Set-VMHostService -Policy “off”

##Enable Lockdown Mode
#

($hst| get-view).EnterLockdownMode() | get-vmhost | select Name,@{N=”LockDown”;E={$_.Extensiondata.Config.adminDisabled}} | ft -auto Name LockDown

}

else {write-host “Host must be in Maintenance Mode”}