Skip to content

Instantly share code, notes, and snippets.

@XPlantefeve
Created June 11, 2015 13:04
Show Gist options
  • Select an option

  • Save XPlantefeve/61c63578faa36b0399a7 to your computer and use it in GitHub Desktop.

Select an option

Save XPlantefeve/61c63578faa36b0399a7 to your computer and use it in GitHub Desktop.
get-DomainAdminLastLogon
$domainControllers = Get-ADDomainController -Filter *
Get-ADGroupMember -Identity 'Domain Admins' -Recursive | ForEach-Object -Process {
$user = $_
$domainControllers |
ForEach-Object -Process {
Get-ADUser $user.SamAccountName -Server $_.Name -Properties lastLogon, cn, employeeNumber, accountExpires, PasswordNeverExpires, Enabled, LockedOut, pwdLastSet
} |
Sort-Object -Property LastLogon |
Select-Object -Last 1 -Property SamAccountName,
@{ name = 'LastLogon' ; expression = { [DateTime]::FromFileTime($_.LastLogon) } },
cn, employeeNumber,
@{ name = 'accountExpires' ; expression = { [DateTime]::FromFileTime($_.accountExpires) } },
PasswordNeverExpires, Enabled, LockedOut,
@{ name = 'pwdLastSet' ; expression = { [DateTime]::FromFileTime($_.pwdLastSet) } }
} | Export-Csv .\banana.csv
@XPlantefeve

Copy link
Copy Markdown
Author

Gets real last logon time for every domain admin by interrogating every DC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment