Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. $NumDays = 0
  2. $LogDir = "Last-Logon.csv"
  3.  
  4. $currentDate = [System.DateTime]::Now
  5. $currentDateUtc = $currentDate.ToUniversalTime()
  6. $lltstamplimit = $currentDateUtc.AddDays(- $NumDays)
  7. $lltIntLimit = $lltstampLimit.ToFileTime()
  8. $adobjroot = [adsi]''
  9. $objstalesearcher = New-Object System.DirectoryServices.DirectorySearcher($adobjroot)
  10. $objstalesearcher.filter = "(&(objectCategory=person)(objectClass=user)(lastLogonTimeStamp<=" + $lltIntLimit + "))"
  11.  
  12. $users = $objstalesearcher.findall() | select `
  13. @{e={$_.properties.cn};n='Display Name'},`
  14. @{e={$_.properties.samaccountname};n='Username'},`
  15. @{e={[datetime]::FromFileTimeUtc([int64]$_.properties.lastlogontimestamp[0])};n='Last Logon'},`
  16. @{e={[string]$adspath=$_.properties.adspath;$account=[ADSI]$adspath;$account.psbase.invokeget('AccountDisabled')};n='Account Is Disabled'}
  17.  
  18. $users | Export-CSV -NoType $LogDir
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement