Move a host into a cluster

This function pulls a list of hosts from your vCenter that are currently in maintenance mode and moves them into your previous selected cluster.
Again this uses my usual variables, specifically:
VP-MoveHostCluster – Function Name
$Global:DCChoice – DC Choice
$Global:CLUChoice – Cluster Choice

function VP-MoveHostCluster
$hosts = Get-datacenter $Global:DCChoice | get-vmhost | Where {$_.ConnectionState -eq "Maintenance"}
Write-Host " ================ Select host to move ================" -ForegroundColor green
$i = 1
$hosts | ForEach-Object -Process {
Write-Host " $i $($_.Name)"
$selection = Read-Host "Please make a selection (Q to Quit)"
if($selection -eq 'Q'){
$HostChoice = $hosts[$selection -1].Name
Write-Host " Moving $HostChoice into $Global:CLUChoice"
Start-Sleep -Second 1
Move-VMHost $HostChoice -Destination $Global:CLUChoice


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.