VMware Cloud Community
antoniogemelli
Hot Shot
Hot Shot

Get logon history

Hello,

I need a script to get a csv with logon history in the last 6 months,

Username

Login date

Logout date

Ip source (from where user login)

Thanks

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

What is the retention period for events in your environment?


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

Reply
0 Kudos
antoniogemelli
Hot Shot
Hot Shot

Hi LucD

I can see is set on 60 days.

Reply
0 Kudos
LucD
Leadership
Leadership

Then you will only be able to collect data for the last 60 days.

Something like this

$events = 'UserLogoutSessionEvent'

$start = (Get-Date).AddMonths(-6)

Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) -Server mvcs001 |

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

    Sort-Object -Property CreatedTime |

Select UserName,IPAddress,LoginTime,

    @{N='LogoutTime';E={[DateTime]($_.FullFormattedMessage -replace '.+login time: (.*), number.+','$1')}}


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

Reply
0 Kudos