Sometime s you need to find AD users in a particular OU who have logged on to any system in past 90 days .
I found this powershell query online that helped me to create a html report for all users with the logon times.
$oldDate = (Get-Date).AddDays(-90).ToFileTime().toString()
Get-ADUser -SearchBase 'OU=Users,dc=domain,dc=com' -Properties lastlogontimestamp -LDAPFilter "(lastlogontimestamp>=$oldDate)" |
select @{n='User';e={$_.name}}, @{n='LastLogOn';e={[datetime]::FromFileTime($_.lastlogontimestamp)}} |
ConvertTo-Html -Title 'Recent Users' | Out-File 'RecentUsers.html'
Invoke-Item 'RecentUsers.html'
Hope this helps.
I found this powershell query online that helped me to create a html report for all users with the logon times.
$oldDate = (Get-Date).AddDays(-90).ToFileTime().toString()
Get-ADUser -SearchBase 'OU=Users,dc=domain,dc=com' -Properties lastlogontimestamp -LDAPFilter "(lastlogontimestamp>=$oldDate)" |
select @{n='User';e={$_.name}}, @{n='LastLogOn';e={[datetime]::FromFileTime($_.lastlogontimestamp)}} |
ConvertTo-Html -Title 'Recent Users' | Out-File 'RecentUsers.html'
Invoke-Item 'RecentUsers.html'
Hope this helps.
Comments
Post a Comment