Export Last User Profile access time

Export Last User Profile access time

#Find all the user profiles
$users = Get-ChildItem "C:\Users"

#Loop through each profile hive and pull last access time
foreach($user in $users)
{
$userName = $user.Name
$AccessTime = Get-Item -force “C:\Users\$userName\Downloads” | Select LastWriteTime
$UserProfile = $userName
New-Object -TypeName PSCustomObject -Property @{
Accesstime = $AccessTime.LastWriteTime
Username = $UserProfile
} | Export-Csv -Path C:\temp\profiles3.csv -NoTypeInformation -Append

}

Leave a Reply

Your email address will not be published. Required fields are marked *