Record the ESXi automation configuration script, script features and scripts as follows:
############################################################################################################### ######## $FileName: esx_conf.ps1## $Version: 1.2## $Description: Installing ESXi5, CSC customized## v1.1: commentaries added, TST references removed## v1.2: nfs volumes renamed, vmnic numbers modified## v1.3: vcenter, dc and cluster deleted ## ########## ############################################################################################################# $Author: ## $CreationDate: 13-march-2012## $LastModifiedDate: 21- january-2013## $Modified by : ###################################################### ############################################################################################################################# ######################################################## esx_conf.ps1 # # ndsi esxi post config ## csc customized # load the vi toolkit # if (-not (get-pssnapin | where-object {$_. name -eq "VMware.VimAutomation.Core"})) { add-pssnapin vmware.vimautomation.core } # variables ## site trigram to be deployed /!\ need to be configured /! $Site _trigram= "SWD" # fqdn or ip of esx server /!\ need to be configured /! $newhost = "10.68.114.13" # esx server vmotion ip /!\ need to be configured /! $ipvmotion = "10.68.114.14" # esx server vmotion mask /!\ need to be configured /! $netmask 0 = "255.255.254.0" # ESX server vmkernel ip 1 for nfs /!\ need to be configured /! $ipnfs 1 = "192.168.160.177" # esx server vmkernel ip 2 for nfs /!\ need to be configured /! $ipnfs 2 = "192.168.161.177" # ESX server VMkernel MASK for NFS /!\ NEED TO BE configured /! $netmask 1 = "255.255.255.0" # nas ctrla vsphere vfiler ip 1 /!\ NEED TO BE CONFIGURED /!# $ipnfs 3 = "192.168.162.77" # NAS CTRLA Vsphere Vfiler IP 2 /!\ NEED TO BE configured /!# $ipnfs 4 = "192.168.163.77" # nas ctrlb vsphere vfiler IP 1 /!\ NEED to be configured /!# $ipnfs 5 = "192.168.162.78" # nas ctrlb vpshere vfiler ip 2 /!\ need to be configured /!# $ipnfs 6 = "192.168.163.78" #AD server name and NAS path $VM 01 = " SWDNM500 "$VM 01_path = "/vol/nfs_vm30_ " + $VM 01 + " _a000000 "# names need to be set on nfs datastore# $nfs 1 = $Site _trigram + "_nfs_vm30_" + $VM 01 + "_a000000" # $nfs 2 = $Site _trigram + "_nfs_vm31_a000001" # $nfs 3 = $Site _trigram + "_nfs_vm30_b000000" # $nfs 4 = $Site _trigram + "_nfs_vm31_b000001" # vlan id need to be tagged on NFS PortGroup$vlanid1 = "3099" $vlanid 2 = "3100" $vlanid 3 = " 3101 "# ntp need to be set in esx server configuration$ntp1 = "Ntp31.example.com" $NTP 2 = "ntp32.example.com" # output log file$log = "C:\esx_conf.log" # start logging #Start-transcript -path $logWrite-host "VARIABLES :" write-hostwrite-host "esx : " $newhostWrite-hostwrite-host "IP VMOTION : " $ipvmotionWrite-hostwrite-host " netmask ip vmotion : " $ netmask0write-hostwrite-host "ip nfs-vmware-1 : " $ipnfs 1write-hostwrite-host " ip nfs-vmware-2 : " $ipnfs 2write-hostwrite-host " IP NAS-A1 NFS1 : " $ipnfs 3write-hostwrite-host " ip nas-a1 nfs2 : " $ ipnfs4write-hostwrite-host "ip nas-b1 nfs1 : " $ipnfs 5write-hostwrite-host "ip nas-b1 nfs2 : " $ipnfs 6write-hostwrite-host "netmask nfs : " $netmask 1write-hostwrite-host "vlan nfs1 : " $vlanid 1write-hostwrite-host "vlan nfs2 : " $vlanid 2write-hostwrite-host " vlan iscsi : " $vlanid 3write-hostwrite-host " DATASTORE NAS-A1 NFS1 : " $nfs 1write-hostwrite-host " datastore nas-a1 nfs2 : " $ nfs2write-hostwrite-host "datastore nas-b1 nfs1 : " $nfs 3write-hostwrite-host "datastore nas-b1 nfs2 : " $nfs 4write-host# connect to new host #Write-host "connexion to new host : " $newhostConnect-viserver $newhost -user root -password passw0rdwrite-host# add vswitch1 # write-host "Add vswitch1" new-virtualswitch -vmhost $newhost -Name vSwitch1 -numports 128 -nic vmniC1,vmnic3 -confirm: $falseWrite-host# delete default port group #Write-host "Delete default vm network port group" get-virtualportgroup -vmhost $newhost -Name "Vm network" | remove-virtualportgroup -confirm: $falseWrite-host# add vmnic2 to vswitch0 #Write-host "Add vmnic2 to vswitch0" get-virtualswitch -vmhost $newhost -name vswitch0 | set-virtualswitch -nic vmnic0,vmnic2 -confirm: $falseWrite-host# add vmotion #Write-host "Add Vmotion port group "new-vmhostnetworkadapter -vmhost $newhost -portgroup vmotion -VirtualSwitch vSwitch0 -IP $ipvmotion -SubnetMask $netmask 0 - vmotionenabled: $true -confirm: $falseWrite-host# add nfs #Write-host "ADD NFS1 and nfs2 port groups "New-vmhostnetworkadapter -vmhost $newhost -PortGroup NFS-VMWARE-1 -VirtualSwitch vswitch0 -ip $ipnfs 1 -subnetmask $netmask 1 -confirm: $falseNew-vmhostnetworkadapter -VMHost $newhost -PortGroup NFS-VMWARE-2 -VirtualSwitch vSwitch0 -IP $ipnfs 2 -subnetmask $netmask 1 -confirm: $falseWrite-host# configure nfs vlan id #Write-host "Configure nfs1 and nfs2 vlan id" Get-virtualportgroup -VMHost $newhost -Name "Nfs-vmware-1" | Set-VirtualPortGroup -VLanId $vlanid 1 -confirm: $falseGet-virtualportgroup -vmhost $newhost -Name "Nfs-vmware-2" | Set-VirtualPortGroup -VLanId $vlanid 2 -confirm: $falseWrite-host# configure Nic Teaming #Write-host "configure nic teaming" get-virtualportgroup - vmhost $newhost -name "Management network" | get-nicteamingpolicy | set-nicteamingpolicy - Makenicactive vmnic0 -confirm: $falseGet-virtualportgroup -vmhost $newhost -Name "Management network" | get-nicteamingpolicy | set-nicteamingpolicy - Makenicstandby vmnic2 -confirm: $falseGet-virtualportgroup -vmhost $newhost -name "VMOTION" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive Vmnic2 -confirm: $falseGet-virtualportgroup -vmhost $newhost -Name "VMOTION" | get-nicteamingpolicy | set-nicteamingpolicy -makenicstandby vmnic0 -confirm:$ falseget-virtualportgroup -vmhost $newhost -Name "Nfs-vmware-1" | Get-nicteamingpolicy | set-nicteamingpolicy -makenicactive vmnic0get-virtualportgroup -VMHost $newhost -Name "Nfs-vmware-1" &Nbsp;| get-nicteamingpolicy | set-nicteamingpolicy -makenicstandby vmnic2 - Confirm: $falseGet-virtualportgroup -vmhost $newhost -Name "Nfs-vmware-2" | get-nicteamingpolicy | set-nicteamingpolicy -makenicactive vmnic2 -confirm:$ falseget-virtualportgroup -vmhost $newhost -Name "Nfs-vmware-2" | get-nicteamingpolicy | set-nicteamingpolicy -makenicstandby vmnic0 -confirm:$ falsewrite-host# add vm port group to vswitch1 #Write-host "Add Vms port group "get-virtualswitch -vmhost $newhost -Name vSwitch1 | New-virtualportgroup -name vms -confirm: $falseWrite-host# add iscsi port group to vswitch1 #Write-host "Add iscsi port group" Get-VirtualSwitch -vmhost $newhost -name vswitch1 | New-virtualportgroup -name iscsi -confirm: $falseGet-virtualportgroup -vmhost $newhost -Name ISCSI | Set-VirtualPortGroup -VLanId $vlanid 3 -confirm:$ falsewrite-host# add ntp servers #Write-host "Add ntp servers" add-vmhostntpserver -vmhost $newhost -NtpServer $ntp 1 -confirm:$ falseadd-vmhostntpserver -vmhost $newhost -NtpServer $ntp 2 -confirm: $falseWrite-host# Creation NFS datastores #Write-host "Creation nfs datastores" # new-datastore -nfs -vmhost $newhost -Name $nfs 1 -path $VM 01_path - nfshost $ipnfs 3# new-datastore -nfs -vmhost $newhost -Name $nfs 2 -path /vol/NFS_VM31_A000001 -NfsHost $ipnfs 4# new-datastore -nfs -vmhost $ newhost -name $nfs 3 -path /vol/nfs_vm30_b000000 -nfshost $ipnfs 5# new-datastore -nfs -vmhost $newhost -Name $nfs 4 - path /vol/nfs_vm31_b000001 -nfshost $ipnfs 6write-host# end logging # Stop-transcript
This article is from the "Mama Sister" blog, please make sure to keep this source http://smallc.blog.51cto.com/926344/1692374
ESXi Automation Configuration Script