Friday, 7 March 2008

Find Last Logon Date

This script will find the last logon date for a supplied user on each DC in your domain and output to a text file. You can then pull the text file say into Excel and sort on the date column to find when the user last logged in.

(You need the Quest AD cmdlets to run this one)

$DomainControllers = Get-QADComputer -computerrole domainController

foreach ($DC in $DomainControllers)

{
$a = Get-QADUser -Service $DC.name 'domain\user'
$dc.name +" " +$a.lastlogon | Out-File -Append C:\Scripts\LastLogon.txt
}

1 comment:

  1. Great post. Thanks.

    The next challenge (for me) is to input this file and display only the most recent date for each user and then output that set to a csv file so we can fully automate thus process.

    Would love to have a single script that disables users who haven't logged on for 60 days...

    ReplyDelete