Skip to content

Instantly share code, notes, and snippets.

@mtellin
Last active April 19, 2017 13:57
Show Gist options
  • Save mtellin/6465225478093d0ff790d1c6e50b7556 to your computer and use it in GitHub Desktop.
Save mtellin/6465225478093d0ff790d1c6e50b7556 to your computer and use it in GitHub Desktop.
# Config
$esx1hostname = "vmw-esx1.mtellin.lab"
$esx1ip = "10.0.2.121"
$esx1mac = "08:9E:01:B4:A1:70"
$esx2hostname = "vmw-esx2.mtellin.lab"
$esx2ip = "10.0.2.122"
$esx2mac = "08:9E:01:B4:A3:02"
$esx3hostname = "vmw-esx3.mtellin.lab"
$esx3ip = "10.0.2.123"
$esx3mac = "08:9E:01:B4:9E:3C"
$esx4hostname = "vmw-esx4.mtellin.lab"
$esx4ip = "10.0.2.124"
$esx4mac = "08:9E:01:93:40:14"
# Put VM names into group order
$group1 = "NET-NSX1","SRV-SQL1","VRL-AUT1","VRL-LOG1","NET-OPS1","NET-VNI1","SRV-VMV1"
$group2 = "NSX_Controller_*","SRV-RDS1","VRL-IAS1","NET-VNI2","DMZ-VSS1"
$group3 = "VRL-ORC1","VRL-BUS1"
#Power on ESXi hosts, wakeonlan installed via brew
wakeonlan -i $esx1ip -p 9 $esx1mac
#Wait until ConnectionState is Connected before continuing on
do
{
Start-Sleep -s 30
Write-Host "Waiting 30 Seconds for host to come online"
}
while (get-vmhost $esx1hostname | Where-object {$_.ConnectionState -ne "Connected"})
wakeonlan -i $esx2ip -p 9 $esx2mac
do
{
Start-Sleep -s 30
Write-Host "Waiting 30 Seconds for host to come online"
}
while (get-vmhost $esx2hostname | Where-object {$_.ConnectionState -ne "Connected"})
wakeonlan -i $esx3ip -p 9 $esx3mac
do
{
Start-Sleep -s 30
Write-Host "Waiting 30 Seconds for host to come online"
}
while (get-vmhost $esx3hostname | Where-object {$_.ConnectionState -ne "Connected"})
wakeonlan -i $esx4ip -p 9 $esx4mac
do
{
Start-Sleep -s 30
Write-Host "Waiting 30 Seconds for host to come online"
}
while (get-vmhost $esx4hostname | Where-object {$_.ConnectionState -ne "Connected"})
# Hosts ready, starting VMs
write-host "Starting Group 1 VMs: " $group1
start-vm $group1 -runasync -confirm:$false
foreach ($vm in $group1) {
start-vm $vm -runasync -confirm:$false
write-host "Waiting for VM Tools to Start"
do {
$toolsStatus = (Get-VM $group1).extensiondata.Guest.ToolsStatus
sleep 15
} until ( $toolsStatus -eq 'toolsOk' )
}
Write-host "Starting Group 2 VMs: " $group2
start-vm $group2 -runasync -confirm:$false
foreach ($vm in $group2) {
start-vm $vm -runasync -confirm:$false
write-host "Waiting for VM Tools to Start"
do {
$toolsStatus = (Get-VM $group2).extensiondata.Guest.ToolsStatus
sleep 15
} until ( $toolsStatus -eq 'toolsOk' )
}
Write-host "Starting Group 3 VMs: " $group3
start-vm $group3 -runasync -confirm:$false
foreach ($vm in $group3) {
start-vm $vm -runasync -confirm:$false
write-host "Waiting for VM Tools to Start"
do {
$toolsStatus = (Get-VM $group3).extensiondata.Guest.ToolsStatus
sleep 15
} until ( $toolsStatus -eq 'toolsOk' )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment