VMware Cloud Community
cmutchle
Enthusiast
Enthusiast

Reconnecting hosts in vCenter

Trying to reconnect a large number of hosts in vCenter after they appeared as Disconnected. All the Google posts I found were 5+ years old and it looks like the syntax has changed. I am using PowerCLI 5.8 R1.

Code:

Get-VMHost | where { $_.ConnectionState -eq "Disconnected" } | % {

    $view = get-view $_.ID

    $arg = New-Object VMware.Vim.HostConnectSpec

    $arg.userName = "root"

    $arg.password = "vmware"

    $arg.force = $true

   

    $view.ReconnectHost_Task($arg)

    Write-Host "." -nonewline

}


The error I am getting states:


“Cannot find an overload for “ReconnectHost” and the argument count: “1”


Any ideas how to sort this?

Reply
0 Kudos
2 Replies
gcanales
Enthusiast
Enthusiast

Have you tried?

$hosts = Get-VMHost | where { $_.ConnectionState -eq "Disconnected" }

Set-VMHost -VMHost $hosts -State "Connected"


Set-VMHost - vSphere PowerCLI Cmdlets Reference

cmutchle
Enthusiast
Enthusiast

gcanales,

Thank you. I was trying to make it more complicated than it needed to be. This got me on the write track and what ended up working was:

$MyHosts = Get-VMHost | where { $_.ConnectionState -eq "Disconnected" }

foreach ($h in $MyHosts) {

  Set-VMHost -VMHost $h -State Connected -RunAsync

}

--

Chris.

Reply
0 Kudos