SHARE
TWEET

Untitled

a guest Dec 9th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top