...hopefully some useful VMware related stuff

Initial ESXi Setup Script

06/01/2011 10:00

Automates the initial setup of an ESXi host after first installation and IP addressing.

 

First connects to ESXi host

 

NETWORKING:

Adds second vmnic to vSwitch0

Creates a second vSwitch (vSwitch1) with port group LAN and assigns 4 vmnics to it

Moves all VirtualMachines if exist to LAN portgroup and removes default VM Network portgroup

Renames Management Network portgroup to MGMT

Creates third vSwitch (vSwitch2) with an ISOLATED portgroup and no vmnics assigned

 

TIME CONFIGURATION:

Adds the following NTP time servers to the host:

0.vmware.pool.ntp.org

1.vmware.pool.ntp.org

2.vmware.pool.ntp.org

 

STORAGE:

Renames the default datastore 'datastore' to 'ESX1_local'

 

SCRIPT:

Download

 

#Initial Setup Script for individual ESXi Host
#20110106
#https://www.a2-alpha.co.uk

 

#Set Credentials and Host

$ESXiHost = "192.168.0.1"
$Username = "root"
$Password = "Password"

 

#Connect to host

Connect-VIServer -Server $ESXiHost -User $Username -Password $Password

 

#Add additional NIC to vSwitch0

$vmnics = New-Object System.Collections.ArrayList
$vmnics.Add("vmnic0")
$vmnics.Add("vmnic2")
Set-VirtualSwitch -VirtualSwitch "vSwitch0" -Nic $vmnics -Confirm:$false

 

#Create vSwitch1

New-VirtualSwitch -Name "vSwitch1" -VMHost (Get-VMHost) -NumPorts "64"

 

#Create PortGroup LAN on vSwitch1

New-VirtualPortGroup -Name "LAN" -VirtualSwitch "vSwitch1"

 

#Add NICs to vSwitch1

$vmnics = New-Object System.Collections.ArrayList
$vmnics.Add("vmnic1")
$vmnics.Add("vmnic3")
$vmnics.Add("vmnic4")
$vmnics.Add("vmnic5")
Set-VirtualSwitch -VirtualSwitch "vSwitch1" -Nic $vmnics -Confirm:$false

 

#Create vSwitch2

New-VirtualSwitch -Name "vSwitch2" -VMHost (Get-VMHost) -NumPorts "64"

 

#Create PortGroup ISOLATED on vSwitch2

New-VirtualPortGroup -Name "ISOLATED" -VirtualSwitch "vSwitch2"

 

#Rename Management Network to MGMT

$MgPg = Get-VirtualPortGroup -Name "Management Network"
Set-VirtualPortGroup -VirtualPortGroup $MgPg -Name "MGMT"

 

#Move all VMs to LAN portgroup

$VMPg = get-virtualportgroup -Name "LAN"
ForEach($VM in (Get-VM))
{
    $netadapters = get-networkadapter -VM $VM
    foreach($netadapter in $netadapters)
    {
    set-networkadapter -NetworkAdapter $netadapter -NetworkName $VMPg -StartConnected:$TRUE -confirm:$false | Out-Null
    }
}

 

#Remove PortGroup VM Network

$VMNPg = Get-VirtualPortGroup -Name "VM Network"
Remove-VirtualPortGroup -VirtualPortGroup $VMNPg -Confirm:$false

 

#Add NTP Servers to Host

$ntpservers = New-Object System.Collections.ArrayList
$ntpservers.Add("0.vmware.pool.ntp.org")
$ntpservers.Add("1.vmware.pool.ntp.org")
$ntpservers.Add("2.vmware.pool.ntp.org")
Add-VmHostNtpServer -VMHost $ESXiHost -NtpServer $NTPServers

 

#Rename default datastore to ESX1_local

$ds = Get-Datastore -Name "datastore"
Set-Datastore -Datastore $ds -Name "ESX1_local"

Comments

No comments found.

Search site