Love this.
This
script uses the DirectorySearcher object to search for all users in Active
directory. It then walks through the user accounts and determines the last logon
date.
The key point of the script is translating the [int64] number into
something that can be read.
$searcher
= New-Object DirectoryServices.DirectorySearcher([adsi]"")
$searcher.filter
= "(objectclass=user)"
$users
= $searcher.findall()
Foreach($user
in $users)
{
if($user.properties.item("lastLogon")
-ne 0)
{
$a =
[datetime]::FromFileTime([int64]::Parse($user.properties.item("lastLogon")))
"$($user.properties.item(`"name`")) $a"
}
}
Got this from the Technet script center:
No comments:
Post a Comment