Reconnect ESX hosts using PowerShell

This week I ran into problems with vCenter server and almost all of my VMs were orphaned in vCenter. To resolve this issue I needed to disconnect/connect each ESX host. Because I hate doing repetitive tasks I created a little PowerShell script that I wanted to share with you.

# Variables
$VCServer = "vcserver.yourdomain.local"
$password = "rootPassword"

#Connect to vCenter Server
$VC = Connect-VIServer $VCServer

get-vmhost | % {
    $view = get-view $
    $arg = new-object VMware.Vim.HostConnectSpec
    $arg.userName = "root"
    $arg.password = $password
    $arg.force = $true


Disconnect-VIServer -Confirm:$false

Ofcourse I got a little help from the VMware Community Here

Related posts:

  1. Bulk change your ESX root password Tweet Have you ever been facing your security department demanding you to change your ESX root password? Well I did. At the current site there’s a strict security policy where...
  2. ESX console password aging Tweet Yesterday I did a post on how to change your ESX root password using a Powershell script and told you that I, as a good administrator, didn’t change my...
  3. Setting custom attributes with VMware PowerCLI Tweet Last week I wanted to extend my vCenter with some extra custom attributes on my VMs. This would extend the usability of the Export List feature for reporting purposes....
  4. New version of the Powershell Healthcheck script released Tweet Ivo Beerens published a new version of his Powershell Healthcheck script. Features: - VMware ESX server Hardware and version          - VMware vCenter version     - Cluster information (Updated)    ...
  5. Unable to login to your ESX server Tweet Ivo Beerens posted this article last week on the defunct cimservera processes that render an ESX Host unmanageable. See also this VMWare KB Article. Symptoms include: Unable to log...

1 Comment on “Reconnect ESX hosts using PowerShell”

  1. #1 DJ7777
    on Aug 30th, 2012 at 2:15 pm

    This is an awesome script, however after upgrading to ESXi 4.1 it doesnt reconnect. I am trying to change the VC to another machine and connect to the same database, I think it gives a command that the host is managed by another VC. Any solution for this ?

Leave a Comment