$Days = 35
$DateBound = (Get-Date).AddDays(-$Days)
$OutFile = "c:\temp\OldUsers.csv"
Get-ADComputer -Filter * -Properties lastlogontimestamp |
Select *,@{Name="LastLogonDate"; Expression = {[DateTime]::FromFileTime($_.lastlogontimestamp)}} |
?{$_.LastLogonDate -lt $DateBound} |
Select Name,lastLogonDate |
Export-Csv -Path $OutFile -NoTypeInformation
https://blogs.technet.microsoft.com/askds/2009/04/15/the-lastlogontimestamp-attribute-what-it-was-designed-for-and-how-it-works/
Open in new window