VMware Cloud Community
Spectrum1981
Enthusiast
Enthusiast
Jump to solution

State of host

Hello togehter,

i have a strange question.

I know the states of host returned by the powercli. Connected, Disconnected and Maintenance.

But when i put a host in maintenance with 1TB RAM it takes a long time. During this time our skripts can´t deploy new VM´s because the state is returned as connected.

But when the host on the way to Maintenance the CLI output looks likes this:

New-VM        Operation is not valid due to the current state of the object.

So the vCenter has got another status ...

How can i get the status? Any Idea?

Thanks Rainer

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Afaik, this is not a property that you can retrieve.

The CreateVM-Task method receives an InvalidState fault from the vSphere server.

What could help is to query the disabled methods.

The moment you set an ESXi host to maintenance mode, the EnterMaintenanceMode_Task method will appear in the list.

$esx = Get-VMHost -Name MyEsx

if($esx.ExtensionData.DisabledMethod | where {$_ -match "EnterMaintenanceMode_Task"}){

    "ESXi is switching to maintenance mode"

}

else{

    "Go ahead, create a VM"

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Afaik, this is not a property that you can retrieve.

The CreateVM-Task method receives an InvalidState fault from the vSphere server.

What could help is to query the disabled methods.

The moment you set an ESXi host to maintenance mode, the EnterMaintenanceMode_Task method will appear in the list.

$esx = Get-VMHost -Name MyEsx

if($esx.ExtensionData.DisabledMethod | where {$_ -match "EnterMaintenanceMode_Task"}){

    "ESXi is switching to maintenance mode"

}

else{

    "Go ahead, create a VM"

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Spectrum1981
Enthusiast
Enthusiast
Jump to solution

Wonderfull!

Thats what i am looking for!

Big Thanks from Germany!

Rainer

Reply
0 Kudos
Spectrum1981
Enthusiast
Enthusiast
Jump to solution

Hi!

One more question. Is it possible to get alle host in a cluster except the servers are going to maintenance?

$esx = get-cluster Test-Cluster | Get-VMHost | Where-Object {$_.ExtensionData.DisabledMethod -notmatch "EnterMaintenanceMode_Task"}

This is nor working? Why?

$esx = get-cluster Test-Cluster | Get-VMHost | Where-Object {$_.ExtensionData.DisabledMethod -match "EnterMaintenanceMode_Task"}

This will give me all host that are on the way to maintencane.

Rainer

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The DisabledMethod property is an array, so if one element does not match, the VMHost object will get true.

A quick fix is to join all the elements in the array together to 1 string, and then check if the methodname is present in the string.

Something like this

Get-Cluster Test-Cluster | Get-VMHost | where {[string]::Join(',',$_.ExtensionData.DisabledMethod) -notmatch "EnterMaintenanceMode_Task"}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos