使用directorysearcher时重复

时间:2015-11-10 14:49:36

标签: powershell active-directory directorysearcher

我有一个脚本使用DirectorySearcher来查询Active Directory,每天约有大约13,000个用户。

我被告知我的报告中有重复项,但我无法弄清楚原因。

重复项通常出现在报告的末尾,到目前为止已有6-7位用户。这些用户与用户之间的唯一区别他们之前在报告中的条目是他们的上一次登录时间已经改变(时间是脚本最初启动后的几秒钟)

   #Get date for 3months back in datetime format
   $Date = (Get-Date).AddDays(-90)
   # Correct for daylight savings.
   If ($Date.IsDaylightSavingTime)
   {$Date = $Date.AddHours(-1)}
   # Convert the datetime value, in UTC, into the number of ticks since
   # 12:00 AM January 1, 1601.
   $Value = ($Date.ToUniversalTime()).Ticks - ([DateTime]"January 1, 1601").Ticks

   $Searcher = New-Object DirectoryServices.DirectorySearcher
   $Searcher.PageSize = 30000
   $Searcher.Filter = "(&(&(objectCategory=person)(objectClass=user))(lastLogonTimeStamp>=$value)(pwdLastSet>=$value)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"
   $Searcher.SearchRoot = 'LDAP://dc=contoso,dc=net'
   $results = $Searcher.FindAll() 

   foreach ($result in $results)
   {      
    # Fetches different attributes for each user
    # which is then appended to a .csv file via Add-Content
}

感觉就像我根据他们上一次登录时间被更改的事实识别其他用户..有没有人知道这件事?也许

我如何禁用此行为?

该脚本在06:00:00运行。

以下是重复条目的最后登录时间

10/31/2015 06:00:24
10/31/2015 06:00:32 
10/31/2015 06:02:07 
10/31/2015 06:05:01 
10/31/2015 06:06:05 
10/31/2015 06:08:19 
10/31/2015 06:08:36 

0 个答案:

没有答案
相关问题