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
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}}
Get-vmhost | Get-VIEvent | Where {$_.fullFormattedMessage -like "*has entered maintenance mode*"}
Get-vmhost | Get-annotation
is there any way these timings can be obtained even if the event logs get cleared ?
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
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"?
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}}