Hello Powecli Guru's
I wanted to know if someone has any script that can read a Text or CSV file and put host into maintenance mode
1. Add Txt file put host into maintenance mode
2. Wait for the VM's to be migrated
3. Check if Host in maintenance mode
4. If run additional powercli commands i.e some commands within the script
5. Exit maintenance mode
6. Wait for 10 minutes until the cluster is balanced and make sure the host is out of maintenance mode
7. add the next host into maintenance mode and repeat process
Repeat until all hosts are remediated
Can someone help me with this please
Many thanks
RXJ
Something along these lines?
Get-Content -Path .\esxnames.txt -PipelineVariable esxName |
ForEach-Object -Process {
$esx = Get-VMHost -Name $esxName
Set-VMHost -VMHost $esx -State Maintenance -Confirm:$false -RunAsync | Out-Null
while($esx.State -ne 'Maintenance'){
sleep 5
$esx = Get-VMHost -Name $esx.Name
}
# Run additional commands
Set-VMHost -VMHost $esx -State Connected -Confirm:$false -RunAsync | Out-Null
while($esx.State -ne 'Connected'){
sleep 5
$esx = Get-VMHost -Name $esx.Name
}
Start-Sleep -Seconds 10*60
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Something along these lines?
Get-Content -Path .\esxnames.txt -PipelineVariable esxName |
ForEach-Object -Process {
$esx = Get-VMHost -Name $esxName
Set-VMHost -VMHost $esx -State Maintenance -Confirm:$false -RunAsync | Out-Null
while($esx.State -ne 'Maintenance'){
sleep 5
$esx = Get-VMHost -Name $esx.Name
}
# Run additional commands
Set-VMHost -VMHost $esx -State Connected -Confirm:$false -RunAsync | Out-Null
while($esx.State -ne 'Connected'){
sleep 5
$esx = Get-VMHost -Name $esx.Name
}
Start-Sleep -Seconds 10*60
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you so much LucD