Lab StartUp Script – Using PowerCLI – VirtuallyThatGuy

This is a handy script I was playing with to startup my lab remotely. I hope you find some of the commands useful.

​​ Start-Transcript -Path C:\lab\StartUp.txt

 

##start-up script

#$cred = Get-Credential

$vCenters = MainHost01.lab.local

 

Connect-Viserver MainHost01.lab.local -User root -Password StandUpIfYouHateTottenham

#Connect-VIServer $vCenters -Credential $cred

cls

 

get-vmhost | Set-VMHost -state connected -confirm:$false

 

$VCSA = "LAB-vCenter01.lab.local","LAB-vCenter02.lab.local"

$DC01 = "LAB-VEEAM" ,"LAB-DC01","LAB-KEMP01","LAB-DC02"

$vROPS = "LAB-vROPS-Master","LAB-vROPSRemote01","LAB-vROPSRemote02","LAB-vROPS-Replica", "LAB-APPCOLLECTOR"

$vStorageVMs = "LAB-vStorage01","LAB-vStorage02"

$LABHosts = "LAB-ESXi01.lab.local","LAB-ESXi02.lab.local","LAB-ESXi03.lab.local","LAB-ESXi04.lab.local","LAB-ESXi05.lab.local","LAB-ESXi06.lab.local"

$NestedVMs = "LAB-ESXi07.lab.local","LAB-ESXi08.lab.local","LAB-ESXi09.lab.local","LAB-ESXi10.lab.local","LAB-ESXi11.lab.local","LAB-ESXi12.lab.local"

 

get-vm $vStorageVMs | ?{$_.powerstate -like "*off*"} | start-vm

Start-Sleep -Seconds 60

 

get-vm $VCSA | ?{$_.powerstate -like "*off*"} | start-vm

Start-Sleep -Seconds 60

 

get-vm $DC01 | ?{$_.powerstate -like "*off*"} | start-vm

Start-Sleep -Seconds 60

 

get-vm $vROPS | ?{$_.powerstate -like "*off*"} | start-vm

Start-Sleep -Seconds 60

 

get-vm $LABHosts | ?{$_.powerstate -like "*off*"} | start-vm

Start-Sleep -Seconds 120

 

disConnect-Viserver MainHost01.lab.local -confirm:$false

 

 

$vCenters = "lab-vcenter01.lab.local", "lab-vcenter02.lab.local"

 

Connect-VIServer $vCenters -User rboadi -Password StandUpIfYouHateTottenham

 

get-vmhost $LABHosts | Set-VMHost -state connected -confirm:$false

 

####

Start-Sleep -Seconds 600

 

 

#### Start Nested Lab After 15 Mins of Main LAB

 

get-vm $NestedVMs |?{$_.powerstate -like "*off*"} | start-vm

 

 

$NestedHost = "LAB-ESXi10.lab.local","LAB-ESXi11.lab.local","LAB-ESXi12.lab.local","LAB-ESXi08.lab.local","LAB-ESXi09.lab.local","LAB-ESXi07.lab.local"

Start-Sleep -Seconds 600

 

get-vmhost $NestedHost | Set-VMHost -state connected -confirm:$false

 

disConnect-VIServer $vCenters -Confirm:$false

 

$vCenters = "lab-vcenter01.lab.local", "lab-vcenter02.lab.local"

 

#Connect-VIServer $vCenters -Credential $cred

 

Connect-VIServer $vCenters -User rboadi -Password StandUpIfYouHateTottenham

 

 

$VCSA = "LAB-vCenter01.lab.local","LAB-vCenter02.lab.local"

$DC01 = "LAB-VEEAM" ,"LAB-DC01","LAB-KEMP01"

$vROPS = "LAB-vROPS-Master","LAB-vROPSRemote01","LAB-vROPSRemote02","LAB-vROPS-Replica"  ​​ ​​ ​​​​ 

$vStorageVMs = "LAB-vStorage01","LAB-vStorage02"

$LABHosts = "LAB-ESXi01.lab.local","LAB-ESXi02.lab.local","LAB-ESXi03.lab.local","LAB-ESXi04.lab.local","LAB-ESXi05.lab.local","LAB-ESXi06.lab.local"

$NestedVMs = "LAB-ESXi07.lab.local","LAB-ESXi08.lab.local","LAB-ESXi09.lab.local","LAB-ESXi10.lab.local","LAB-ESXi11.lab.local","LAB-ESXi12.lab.local"

 

get-vmhost $LABHosts | Get-VMHostStorage -RescanAllHba -RescanVmfs -Refresh

 

get-vmhost $LABHosts | Set-VMHost -state connected -confirm:$false

 

get-vmhost $LABHosts | get-vm |?{$_.powerstate -like "*off*"} | start-vm

 

Start-Sleep -Seconds 60

 

get-vmhost $LABHosts | get-vm |?{$_.powerstate -like "*off*"} | start-vm

 

Start-Sleep -Seconds 600

 

Get-Cluster PROD-NESTED-vSAN-Cluster | Get-VMHost | Set-VMHost -state connected -confirm:$false

 

Get-Cluster PROD-NESTED-vSAN-Cluster | start-vm ​​ 

 

 

Stop-Transcript

 

cls

Start-Transcript -Path C:\lab\StartUp.txt

Start-Sleep -Seconds 600

##start-up script
#$cred = Get-Credential
$vCenters = MainHost01.lab.local

Connect-Viserver MainHost01.lab.local -User root -Password StandUpIfYouHateTottenham
#Connect-VIServer $vCenters -Credential $cred
cls


Start-Sleep -Seconds 300

##start-up script
#$cred = Get-Credential
$vCenters = MainHost01.lab.local

Connect-Viserver MainHost01.lab.local -User root -Password StandUpIfYouHateTottenham
#Connect-VIServer $vCenters -Credential $cred
cls


get-vmhost | Set-VMHost -state connected -confirm:$false  -ErrorAction SilentlyContinue 

$VCSA = "LAB-vCenter01.lab.local","LAB-vCenter02.lab.local" 
$DC01 = "LAB-VEEAM" ,"*DC01*","LAB-KEMP01","LAB-DC01","LAB-DC02"
$vROPSMaster = "LAB-vROPS-Master"
$vROPSReplica = "LAB-vROPS-Replica"
$vROPS = "LAB-vROPSRemote01","LAB-vROPSRemote02", "LAB-APPCOLLECTOR"
$vStorageVMs = "*Storag*","LAB-vStorage01","LAB-vStorage02"
$LABHosts = "LAB-ESXi01.lab.local","LAB-ESXi02.lab.local","LAB-ESXi03.lab.local","LAB-ESXi04.lab.local","LAB-ESXi05.lab.local","LAB-ESXi06.lab.local"
$NestedVMs = "LAB-ESXi07.lab.local","LAB-ESXi08.lab.local","LAB-ESXi09.lab.local","LAB-ESXi10.lab.local","LAB-ESXi11.lab.local","LAB-ESXi12.lab.local"
$NestedHost = "LAB-vSAN-ESXi01.lab.local","LAB-vSAN-ESXi02.lab.local","LAB-vSAN-ESXi03.lab.local"

get-vm $DC01 | ?{$_.powerstate -like "*off*"} | start-vm   -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 60

get-vm $vStorageVMs | ?{$_.powerstate -like "*off*"} | start-vm   -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 60

get-vm $VCSA | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 60

get-vm $vROPSMaster | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 60

get-vm $vROPSReplica | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 60

get-vm $vROPS | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 60


get-vm $LABHosts | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 60

#disConnect-Viserver MainHost01.lab.local -confirm:$false -ErrorAction SilentlyContinue 

####
Start-Sleep -Seconds 300


$vCenters = "lab-vcenter01.lab.local", "lab-vcenter02.lab.local"

Connect-VIServer $vCenters -User rboadi@lab.local -Password StandUpIfYouHateTottenham -ErrorAction SilentlyContinue 


get-vmhost $LABHosts | Set-VMHost -state connected -confirm:$false -ErrorAction SilentlyContinue 


#### Start Nested Lab After 15 Mins of Main LAB

get-vm $NestedVMs |?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 

$NestedHost = "LAB-ESXi10.lab.local","LAB-ESXi11.lab.local","LAB-ESXi12.lab.local","LAB-ESXi08.lab.local","LAB-ESXi09.lab.local","LAB-ESXi07.lab.local"
Start-Sleep -Seconds 5

get-vmhost $NestedHost | Set-VMHost -state connected -confirm:$false -ErrorAction SilentlyContinue 

get-vm $DC01 | ?{$_.powerstate -like "*off*"} | start-vm   -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

get-vm $vStorageVMs | ?{$_.powerstate -like "*off*"} | start-vm   -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

get-vm $VCSA | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

get-vm $vROPSMaster | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

get-vm $vROPSReplica | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

get-vm $vROPS | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5


get-vm $LABHosts | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

Connect-VIServer $vCenters -Confirm:$false -ErrorAction SilentlyContinue 

$vCenters = "lab-vcenter01.lab.local", "lab-vcenter02.lab.local"

#Connect-VIServer $vCenters -Credential $cred

Connect-VIServer $vCenters -User rboadi@lab.local -Password StandUpIfYouHateTottenham -ErrorAction SilentlyContinue 


$vCenters = "lab-vcenter01.lab.local", "lab-vcenter02.lab.local"

Connect-VIServer $vCenters -User rboadi@lab.local -Password StandUpIfYouHateTottenham -ErrorAction SilentlyContinue 


$VCSA = "LAB-vCenter01.lab.local","LAB-vCenter02.lab.local" 
$DC01 = "LAB-VEEAM" ,"LAB-DC01","LAB-KEMP01"
$vROPS = "LAB-vROPS-Master","LAB-vROPSRemote01","LAB-vROPSRemote02","LAB-vROPS-Replica"     
$vStorageVMs = "LAB-vStorage01","LAB-vStorage02"
$LABHosts = "LAB-ESXi01.lab.local","LAB-ESXi02.lab.local","LAB-ESXi03.lab.local","LAB-ESXi04.lab.local","LAB-ESXi05.lab.local","LAB-ESXi06.lab.local"
$NestedVMs = "LAB-ESXi07.lab.local","LAB-ESXi08.lab.local","LAB-ESXi09.lab.local","LAB-ESXi10.lab.local","LAB-ESXi11.lab.local","LAB-ESXi12.lab.local"


$vCenters = "lab-vcenter01.lab.local", "lab-vcenter02.lab.local"

Connect-VIServer $vCenters -User rboadi@lab.local -Password StandUpIfYouHateTottenham -ErrorAction SilentlyContinue 



get-vmhost $LABHosts | Get-VMHostStorage -RescanAllHba -RescanVmfs -Refresh -ErrorAction SilentlyContinue 

get-vmhost $LABHosts | Set-VMHost -state connected -confirm:$false -ErrorAction SilentlyContinue 

get-vmhost $LABHosts | get-vm |?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 

Start-Sleep -Seconds 5

get-vmhost $LABHosts | get-vm |?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 

Start-Sleep -Seconds 5


Get-Cluster "*PROD-NESTED-vSAN-Cluster*" | Get-VMHost | Set-VMHost -state connected -confirm:$false -ErrorAction SilentlyContinue 

Get-Cluster "*PROD-NESTED-vSAN-Cluster*" | start-vm   -ErrorAction SilentlyContinue 

Get-Cluster "*MGMT*" | Get-VMHost | get-vm | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 


get-vm $DC01 | ?{$_.powerstate -like "*off*"} | start-vm   -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

get-vm $vStorageVMs | ?{$_.powerstate -like "*off*"} | start-vm   -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

get-vm $VCSA | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

get-vm $vROPSMaster | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

get-vm $vROPSReplica | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

get-vm $vROPS | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5


get-vm $LABHosts | ?{$_.powerstate -like "*off*"} | start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5


$vCenters = "lab-vcenter01.lab.local", "lab-vcenter02.lab.local"

Connect-VIServer $vCenters -User rboadi@lab.local -Password StandUpIfYouHateTottenham -ErrorAction SilentlyContinue 

get-vm | ?{$_.powerstate -like "*off*"}  |  start-vm  -ErrorAction SilentlyContinue 
Start-Sleep -Seconds 5

disConnect-Viserver MainHost01.lab.local -Confirm:$false
disConnect-Viserver MainHost01.lab.local -Confirm:$false -ErrorAction SilentlyContinue
disConnect-Viserver MainHost01.lab.local -Confirm:$false -ErrorAction SilentlyContinue


Stop-Transcript

cls


You May Also Like

About the Author: VirtuallyThatGuy

Leave a Reply

Your email address will not be published. Required fields are marked *