记录一下ESXi自动化配置脚本,脚本功能及脚本如下:
创建站点名称;
配置IP和vmotion IP及子网掩码
配置Vlan
删除默认端口组
增加vSwitch
设置NTP
##################################################################################################################### ## $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 /!\ $netmask0 = "255.255.254.0" # ESX server VMkernel IP 1 for NFS /!\ NEED TO BE CONFIGURED /!\ $ipnfs1 = "192.168.160.177" # ESX server VMkernel IP 2 for NFS /!\ NEED TO BE CONFIGURED /!\ $ipnfs2 = "192.168.161.177" # ESX server VMkernel MASK for NFS /!\ NEED TO BE CONFIGURED /!\ $netmask1 = "255.255.255.0" # NAS CTRLA Vsphere Vfiler IP 1 /!\ NEED TO BE CONFIGURED /!\ # $ipnfs3 = "192.168.162.77" # NAS CTRLA Vsphere Vfiler IP 2 /!\ NEED TO BE CONFIGURED /!\ # $ipnfs4 = "192.168.163.77" # NAS CTRLB Vsphere Vfiler IP 1 /!\ NEED TO BE CONFIGURED /!\ # $ipnfs5 = "192.168.162.78" # NAS CTRLB Vpshere Vfiler IP 2 /!\ NEED TO BE CONFIGURED /!\ # $ipnfs6 = "192.168.163.78" #AD server name and NAS path $VM01 = "SWDNM500" $VM01_PATH = "/vol/NFS_VM30_" + $VM01 + "_A000000" # Names need to be set on NFS DataStore # $nfs1 = $Site_Trigram + "_NFS_VM30_" + $VM01 + "_A000000" # $nfs2 = $Site_Trigram + "_NFS_VM31_A000001" # $nfs3 = $Site_Trigram + "_NFS_VM30_B000000" # $nfs4 = $Site_Trigram + "_NFS_VM31_B000001" # VLAN ID need to be tagged on NFS PortGroup $vlanid1 = "3099" $vlanid2 = "3100" $vlanid3 = "3101" # NTP need to be set in ESX server configuration $ntp1 = "ntp31.example.com" $ntp2 = "ntp32.example.com" # Output log file $log = "c:\esx_conf.log" # start logging # Start-Transcript -Path $log Write-Host "Variables :" Write-Host Write-Host "Esx : " $newhost Write-Host Write-Host "IP vmotion : " $ipvmotion Write-Host Write-Host "Netmask IP vmotion : " $netmask0 Write-Host Write-Host "IP NFS-VMWARE-1 : " $ipnfs1 Write-Host Write-Host "IP NFS-VMWARE-2 : " $ipnfs2 Write-Host Write-Host "IP nas-a1 NFS1 : " $ipnfs3 Write-Host Write-Host "IP nas-a1 NFS2 : " $ipnfs4 Write-Host Write-Host "IP nas-b1 NFS1 : " $ipnfs5 Write-Host Write-Host "IP nas-b1 NFS2 : " $ipnfs6 Write-Host Write-Host "Netmask NFS : " $netmask1 Write-Host Write-Host "VLAN NFS1 : " $vlanid1 Write-Host Write-Host "VLAN NFS2 : " $vlanid2 Write-Host Write-Host "VLAN ISCSI : " $vlanid3 Write-Host Write-Host "Datastore nas-a1 NFS1 : " $nfs1 Write-Host Write-Host "Datastore nas-a1 NFS2 : " $nfs2 Write-Host Write-Host "Datastore nas-b1 NFS1 : " $nfs3 Write-Host Write-Host "Datastore nas-b1 NFS2 : " $nfs4 Write-Host # connect to new host # Write-Host "Connexion to new host : " $newhost Connect-VIServer $newhost -User root -Password passw0rd Write-Host # add vSwitch1 # Write-Host "Add vSwitch1" New-VirtualSwitch -VMHost $newhost -Name vSwitch1 -NumPorts 128 -Nic vmnic1,vmnic3 -Confirm:$false Write-Host # delete default Port Group # Write-Host "Delete default VM Network port group" Get-VirtualPortGroup -VMHost $newhost -Name "VM Network" | Remove-VirtualPortGroup -Confirm:$false Write-Host # add vmnic2 to vSwitch0 # Write-Host "Add vmnic2 to vSwitch0" Get-VirtualSwitch -VMHost $newhost -name vSwitch0 | Set-VirtualSwitch -Nic vmnic0,vmnic2 -confirm:$false Write-Host # add vmotion # Write-Host "Add vmotion port group" New-VMHostNetworkAdapter -VMHost $newhost -PortGroup VMOTION -VirtualSwitch vSwitch0 -IP $ipvmotion -SubnetMask $netmask0 -VMotionEnabled:$true -Confirm:$false Write-Host # add NFS # Write-Host "Add NFS1 and NFS2 port groups" New-VMHostNetworkAdapter -VMHost $newhost -PortGroup NFS-VMWARE-1 -VirtualSwitch vSwitch0 -IP $ipnfs1 -SubnetMask $netmask1 -Confirm:$false New-VMHostNetworkAdapter -VMHost $newhost -PortGroup NFS-VMWARE-2 -VirtualSwitch vSwitch0 -IP $ipnfs2 -SubnetMask $netmask1 -Confirm:$false Write-Host # configure NFS vlan id # Write-Host "Configure NFS1 and NFS2 vlan id" Get-VirtualPortgroup -VMHost $newhost -Name "NFS-VMWARE-1" | Set-VirtualPortGroup -VLanId $vlanid1 -confirm:$false Get-VirtualPortgroup -VMHost $newhost -Name "NFS-VMWARE-2" | Set-VirtualPortGroup -VLanId $vlanid2 -confirm:$false Write-Host # configure Nic Teaming # Write-Host "Configure Nic teaming" Get-VirtualPortGroup -VMHost $newhost -Name "Management Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic0 -Confirm:$false Get-VirtualPortGroup -VMHost $newhost -Name "Management Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic2 -Confirm:$false Get-VirtualPortGroup -VMHost $newhost -Name "VMOTION" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic2 -Confirm:$false Get-VirtualPortGroup -VMHost $newhost -Name "VMOTION" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic0 -Confirm:$false Get-VirtualPortGroup -VMHost $newhost -Name "NFS-VMWARE-1" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic0 Get-VirtualPortGroup -VMHost $newhost -Name "NFS-VMWARE-1" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic2 -Confirm:$false Get-VirtualPortGroup -VMHost $newhost -Name "NFS-VMWARE-2" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic2 -Confirm:$false Get-VirtualPortGroup -VMHost $newhost -Name "NFS-VMWARE-2" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic0 -Confirm:$false Write-Host # add VM Port Group to vSwitch1 # Write-Host "Add VMS port group" Get-VirtualSwitch -VMHost $newhost -Name vSwitch1 | New-VirtualPortGroup -Name VMS -Confirm:$false Write-Host # add ISCSI Port Group to vSwitch1 # Write-Host "Add ISCSI port group" Get-VirtualSwitch -VMHost $newhost -Name vSwitch1 | New-VirtualPortGroup -Name ISCSI -Confirm:$false Get-VirtualPortgroup -VMHost $newhost -Name ISCSI | Set-VirtualPortGroup -VLanId $vlanid3 -confirm:$false Write-Host # add NTP servers # Write-Host "Add NTP servers" Add-VmHostNtpServer -VMHost $newhost -NtpServer $ntp1 -Confirm:$false Add-VmHostNtpServer -VMHost $newhost -NtpServer $ntp2 -Confirm:$false Write-Host # Creation NFS datastores # Write-Host "Creation NFS datastores" # New-Datastore -Nfs -VMHost $newhost -Name $nfs1 -Path $VM01_PATH -NfsHost $ipnfs3 # New-Datastore -Nfs -VMHost $newhost -Name $nfs2 -Path /vol/NFS_VM31_A000001 -NfsHost $ipnfs4 # New-Datastore -Nfs -VMHost $newhost -Name $nfs3 -Path /vol/NFS_VM30_B000000 -NfsHost $ipnfs5 # New-Datastore -Nfs -VMHost $newhost -Name $nfs4 -Path /vol/NFS_VM31_B000001 -NfsHost $ipnfs6 Write-Host # end logging # Stop-Transcript