Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. function getLastLogonTS{
  2. param($username)
  3. $DCs = Get-ADDomainController -Filter *| Select hostname
  4. foreach($d in $DCs) {
  5. $lasttime = $(Get-ADUser -Properties lastlogontimestamp $username -Server $d.hostname).lastlogontimestamp
  6. if($lasttime -gt $lastLogonTimestamp){
  7. $lastLogonTimestamp = $lasttime
  8. }
  9. }
  10. return [datetime]::fromFileTime($lastLogonTimestamp)
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement