VMware Cloud Community
AndersonSimplic
Contributor
Contributor

Hosts in Maintenance Mode -Date and Initiator User by PowerCli

Hello,@LucD

I need to know via which hosts are in maintenance mode, when it was entered, and who did it.

6 Replies
LucD
Leadership
Leadership

0 Kudos
AndersonSimplic
Contributor
Contributor

I'm using this script you made ... it works great, but it doesn't bring the user who made the process. Can you edit this script to also show the user who put the host into maintenance mode?

Function VisualizaHostManutencao{

  

   Get-VMHost | where{$_.ConnectionState -eq 'Maintenance'} | Select Name, @{N='Date';E={

   Get-VIEvent -Entity $_ -MaxSamples ([int]::MaxValue) |

    where{$_ -is [VMware.Vim.EnteredMaintenanceModeEvent]} |

    Sort-Object -Property CreatedTime -Descending |

   Select -First 1 -ExpandProperty CreatedTime

    }}

}

-----------------------------

Example of above script result

Name                             Date

----                                  ----

host2  03/10/2019 14:39:23

host1  03/10/2019 14:39:23

0 Kudos
LucD
Leadership
Leadership

Try like this

Get-VMHost | where{$_.ConnectionState -eq 'Maintenance'} |

Select Name,

    @{N='Date';E={

        $script:maint = Get-VIEvent -Entity $_ -MaxSamples ([int]::MaxValue) |

        where{$_ -is [VMware.Vim.EnteredMaintenanceModeEvent]} |

        Sort-Object -Property CreatedTime -Descending |

        Select -First 1

        $script:maint.CreatedTime

    }},

    @{N='User';E={$script:maint.UserName}}


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

0 Kudos
AndersonSimplic
Contributor
Contributor

Hi, LucD

Look at the result. Don´t bring anything

Name                           Value

----                           -----

E                              $script:maint.UserName

N                              User

0 Kudos
LucD
Leadership
Leadership

Looks like you might have missed a comma at the end of a line somewhere


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

AndersonSimplic
Contributor
Contributor

Thanks

0 Kudos