HI all,
I am working on power CLI script to automate regular tasks and I need some here with putting host to maintenance mode, but there are some prechecks needs to be done on host/cluster before host goes in MM.
*we have DRS set to fully automated
1. Check if there is any Affinity rule/Vm Rules on host. if there is affinity rule need comment output to user to remove it
2.Check if there is any other host is not responding/powered off or is Maintenance mode in a cluster because as per policy not more than one host can be down in cluster, also if there can be logic to check workload like if other hosts are at 90% utilization on compute resource like Memory and CPU and they cannot take the workload.
if no other host down, target host should go to MM.
3. we use vSAN so VsanDataMigrationMode needs to be set to Full before host goes to MM
for 1st I have logic below which will check for affinity rule
$report = foreach($vc in $global:DefaultVIServers){
foreach ($cluster in Get-Cluster -Server $vc){
Get-DrsRule -Cluster $cluster|
Select Name, Type, Enabled,
@{N='vCenter';E={$vc.Name}},
@{N='Cluster';E={$cluster.Name}}
}
}
$report |Export-Csv -Path".\DRSRule-Report-$(Get-Date -Format 'MMdd-HHmm').csv" -NoTypeInformation -UseCulture
for 2nd
$esxName = 'MyEsx'
$esx = Get-VMHost -Name $esxName
$timeout = 0 # No timeout
$evacuatePoweredOffVms = $true
$spec = New-Object -TypeName VMware.Vim.HostMaintenanceSpec
$spec.VsanMode = New-Object -TypeName VMware.Vim.VsanHostDecommissionMode
$spec.VsanMode.ObjectAction = [VMware.Vim.VsanHostDecommissionModeObjectAction]::noAction
$esx.ExtensionData.EnterMaintenanceMode($timeout, $evacuatePoweredOffVms, $spec)
and I am unable to figure out the logic/code for threshold and to check other hosts as I am not into automation,
Any help would be much appreciated.
Thanks!