VMware Cloud Community
SG1234
Enthusiast
Enthusiast
Jump to solution

need to get time host was put in maintenance mode and annotation

Hi -- is it possible to get the time a host was put in maintenance mode and also grab any annotation attached to the ESX host in VC?

thanks

~Sai

Reply
0 Kudos
1 Solution

Accepted Solutions
LittleNickey
Enthusiast
Enthusiast
Jump to solution

Also using "get-vmhost" a second time is redundant since you have piped from get-vmhost: "E={ get-vmhost $_ | get-vievent"

Your command will however return the whole Event object and look something like:

Name                                    Event

----                                    -----

host                      {VMware.Vim.EnteredMaintenanceModeEv...

You can try below instead:

Get-VMHost | ?{$_.ConnectionState -match "Maintenance"} | select Name, @{N="Time put in MaintMode";E={($_ | Get-VIEvent | ?{$_.FullFormattedMessage -like "*has entered maintenance mode*"}).CreatedTime}}

But this can still retrieve multiple events, so one way to only get the last event and time is below:

Get-VMHost | ?{$_.ConnectionState -match "Maintenance"} | select Name, @{N="Time put in MaintMode";E={($_ | Get-VIEvent | ?{$_.FullFormattedMessage -like "*has entered maintenance mode*"} | select -last 1).CreatedTime}}

-- Oskar

View solution in original post

Reply
0 Kudos
5 Replies
kunaludapi
Expert
Expert
Jump to solution

Get-vmhost | Get-VIEvent | Where {$_.fullFormattedMessage -like "*has entered maintenance mode*"}


Get-vmhost | Get-annotation

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
SG1234
Enthusiast
Enthusiast
Jump to solution

is there any way these timings can be obtained even if the event logs get cleared ?

Reply
0 Kudos
SG1234
Enthusiast
Enthusiast
Jump to solution

hi - am trying the following to get the hostname and time it went into maint mode - but somehow the second coloumn is not populating - can someone please correct me whats wrong

[vSphere PowerCLI]get-vmhost  | where-object {$_.connectionstate -match "maint*"} | sele

t @{n="Name of ESX host";e={$_.name}},@{N="time put in maintmode";E={ get-vmhos

$_|get-vievent| Where {$_.fullFormattedMessage -like "*has entered maintenance

mode*"}}}

~Sai Garimella

Reply
0 Kudos
LittleNickey
Enthusiast
Enthusiast
Jump to solution

t @{n="Name of ESX host";e={$_.name}},@{N="time put in maintmode";E={ get-vmhos $_|get-vievent| Where {$_.fullFormattedMessage -like "*has entered maintenance


is this a typo in the code or did you miss to copy the "t"?

-- Oskar
Reply
0 Kudos
LittleNickey
Enthusiast
Enthusiast
Jump to solution

Also using "get-vmhost" a second time is redundant since you have piped from get-vmhost: "E={ get-vmhost $_ | get-vievent"

Your command will however return the whole Event object and look something like:

Name                                    Event

----                                    -----

host                      {VMware.Vim.EnteredMaintenanceModeEv...

You can try below instead:

Get-VMHost | ?{$_.ConnectionState -match "Maintenance"} | select Name, @{N="Time put in MaintMode";E={($_ | Get-VIEvent | ?{$_.FullFormattedMessage -like "*has entered maintenance mode*"}).CreatedTime}}

But this can still retrieve multiple events, so one way to only get the last event and time is below:

Get-VMHost | ?{$_.ConnectionState -match "Maintenance"} | select Name, @{N="Time put in MaintMode";E={($_ | Get-VIEvent | ?{$_.FullFormattedMessage -like "*has entered maintenance mode*"} | select -last 1).CreatedTime}}

-- Oskar
Reply
0 Kudos