how can i improve this script. It works but seems awkward. basically it takes old hosts registered with ip addresses (vmhosts.txt) in vcenter out of a cluster and reregister them with dns names (vmhosts1.txt) instead of ip addresses
I did a little reorganization of your script. I could not test it, but at least it will give you an idea how to organize it in a PowerShell way of doing things.
Connect-VIServer vc Get-Content -Path "C:\vmhosts.txt" | ForEach-Object { Get-VMHost -Name $_ | Set-VMHost -State Disconnected | Remove-VMHost -Confirm:$false } $Cluster = Get-Cluster -Name cluster Get-Content -Path "C:\vmhosts.txt" | ForEach-Object { Add-VMHost -Name $_ -Location $Cluster -User root -Password xxxxx -Confirm:$false -force -RunAsync } Disconnect-VIServer vc -Confirm:$false
Regards, Robert
Message was edited by: RvdNieuwendijk Made an improvement to the script.