Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, February 23, 2015 11:09 AM
I am trying to create a powershell script that will allow me to get the details of a security group and also show me the last login date for a user that is the member of that group.
This is what i have so far:
Get-ADGroupMember -Identity "Outlook Anywhere" -Recursive | Get-ADObject -Properties Name, DisplayName, samAccountName |Export-Csv -path c:\Outlook_Anywhere.csv
This gives me the details of the members but I want to be able to also include the last login date for each user in the group. Can anyone point me in the right direction please?
Thanks
All replies (2)
Monday, February 23, 2015 1:07 PM ✅Answered
Hi Shayne,
this can be done using the LastLogonTimestamp property like this:
Get-ADGroupMember Pub-Service-Neues-Write -Recursive | Get-ADObject -Properties Name, DisplayName, samAccountName, LastLogonTimestamp | Select-Object Name, DisplayName, samAccountName, @{ n = "LastLogonDate"; e = { [System.DateTime]::FromFileTime($_.LastLogonTimeStamp) } } | Export-Csv -Path "C:\Outlook_Anywhere.csv"
What the select does is convert the Timestamp to something a human can read.
Cheers,
Fred
There's no place like 127.0.0.1
Monday, February 23, 2015 2:20 PM ✅Answered
The LasLoginTimeStamp is only accurate to +-14 days. To get an accurate time you must poll all domain controllers Event logs for the logon times.
¯\(ツ)_/¯