Hi Luc,
Good Morning,
could you suggest if following code can be converted to function and can utilized in previous script of upgrading esxi hosts using powercli.
also do yu have simple code for checking prerequisites before putting host in machinate mode.
$destpath=[Environment]::GetFolderPath("Desktop")
$cluster=read-host "specify the cluster name"
$clu=get-cluster $cluster
if($clu.DrsAutomationLevel -eq "fullyautomated")
{
Set-Cluster -Cluster $clu -Drsautomationlevel Manual
}
$hosts=Get-VMHost -Location $clu
$test_vm=read-host "specify the test vm"
Write-Host "Testing vMotion network connectivity by migrating" $TestVM "across the hosts in" $Clu.Name
$TestVM=get-vm $test_vm
$InitialVMHost = $TestVM.VMHost
for ($i=0; $i -le $hosts.GetUpperBound(0); $i++)
{
If ($i -eq $hosts.GetUpperBound(0))
{
$DestHost = $hosts[0]
}
else { $DestHost = $hosts[$i+1] }
Move-VM -VM $TestVM -Destination $DestHost -ErrorVariable +err 2>> $destpath\vMotionNetTest.txt | out-null
}
If ($InitialVMHost -ne $hosts[0]) {
Move-VM -VM $TestVM -Destination $InitialVMHost
}
$datetime = Get-Date
If ($err.count -eq 0) {Write-Output "$datetime Network test completed successfully" >> $destpath\vMotionNetTest.txt}
else
{ Write-Output "$datetime The specified test VM cannot be migrated. Please check vMotionTest.csv file for details" >> $destpath\vMotionNetTest.txt