Reconfigure for HA the PowerShell Way!

With all of my recent ftPerl love, I’ve found that the quickest way to at least start troubleshooting it is to reconfigure the offending host for HA. This is fine if working in a small environment, or on a small number of hosts, but there are a metric ton of these hosts gone sideways all at once, you need a larger hammer. In the words of Duke Nukem “It’s time to PoSH and chew gum, and I’m all outta gum.”

First we had to find out where in the MOB to make the call, and then what the call was. So, poking through the MOB for this, the reconfigure task, is a method made available from the VMHost object. Making this work in PowerShell looks like:

[VI Toolkit] C:\> $vmhostView = get-vmhost | select -first 1 | get-view
[VI Toolkit] C:\> $vmhostView.ReconfigureHostForDAS_Task()

Type                                                             Value
—-                                                             —–
Task                                                             task-49249

So the logical next step was to make this a bit easier to remember, so I wrapped some pipeline magic around it:

reconfigure-ha.ps1

While it doesn’t really justify it’s own script, this makes it much easier to remember & work with.

Questions? Drop a line in the comments.

4 thoughts on “Reconfigure for HA the PowerShell Way!

  • Thanks for the scripting here. I'm new to functions and processes in PowerShell and have been looking for a good reason to try them out. I've tried to modify this to be a function in a script I am writing but having an issue. I was hoping you may be able to see where I've gone astray.

    function ReconfigureHA {
    if ( $_ -isnot [VMware.VimAutomation.Client20.VMHostImpl] ) {
    Write-Error “VMHost expected, skipping object in pipeline.”
    continue
    }
    $vmhostView = $_ | Get-View
    $vmhostView.ReconfigureHostForDAS_Task()
    }

    Get-VMHost -Name “vm14” | ReconfigureHA

    I'm using VESI for my IDE and I'm able to get the Host object to display as $_ but when it Pipes to the function; $_ goes blank on me. Based on what I've read I've appropriately defined the function before calling it (something I find slightly irritating even though I know this is a scripting and not programming language). I was under the impression that the function would natively look for a passed object and not require setting parameters.

    I was able to successfully run the following which will work for my needs but curious as to why the function would not work.

    $vmhost = Get-VMHost -Name “vm14”
    $vmhostView = $vmhost | Get-View
    $vmhostView.ReconfigureHostForDAS_Task()

    The second script here works fantastic thanks to your initial guidance and I'm glad you took the time to post. Any help would be appreciated on making my maiden function voyage successful

  • Thanks for the scripting here. I'm new to functions and processes in PowerShell and have been looking for a good reason to try them out. I've tried to modify this to be a function in a script I am writing but having an issue. I was hoping you may be able to see where I've gone astray.

    function ReconfigureHA {
    if ( $_ -isnot [VMware.VimAutomation.Client20.VMHostImpl] ) {
    Write-Error “VMHost expected, skipping object in pipeline.”
    continue
    }
    $vmhostView = $_ | Get-View
    $vmhostView.ReconfigureHostForDAS_Task()
    }

    Get-VMHost -Name “vm14” | ReconfigureHA

    I'm using VESI for my IDE and I'm able to get the Host object to display as $_ but when it Pipes to the function; $_ goes blank on me. Based on what I've read I've appropriately defined the function before calling it (something I find slightly irritating even though I know this is a scripting and not programming language). I was under the impression that the function would natively look for a passed object and not require setting parameters.

    I was able to successfully run the following which will work for my needs but curious as to why the function would not work.

    $vmhost = Get-VMHost -Name “vm14”
    $vmhostView = $vmhost | Get-View
    $vmhostView.ReconfigureHostForDAS_Task()

    The second script here works fantastic thanks to your initial guidance and I'm glad you took the time to post. Any help would be appreciated on making my maiden function voyage successful

Comments are closed.