Active Directory上次login复制AD服务器

我们需要运行一个查询,这个查询会在n天不活动之后自动禁用一个账户。 我被告知,因为我们有几个AD服务器,如果用户login,让我们说到ADserver1最后的login信息不复制到ADserver2 ..我怎样才能有最后一个login信息跨所有广告服务器复制?

这是由Richard Mueller编写的Powershell脚本,我发现它很有帮助。 它会查询您域中的所有AD服务器,并报告所有用户/计算机的最近login时间,因此可能需要进行一些手动编辑以满足您的需求。 虽然是一个很好的起点。

# PSLastLogon.ps1 # PowerShell script to determine when each user in the domain last # logged on. # # ---------------------------------------------------------------------- # Copyright (c) 2011 Richard L. Mueller # Hilltop Lab web site - http://www.rlmueller.net # Version 1.0 - March 16, 2011 # # This program queries every Domain Controller in the domain to find the # largest (latest) value of the lastLogon attribute for each user. The # last logon dates for each user are converted into local time. The # times are adjusted for daylight savings time, as presently configured. # # You have a royalty-free right to use, modify, reproduce, and # distribute this script file in any way you find useful, provided that # you agree that the copyright owner above has no warranty, obligations, # or liability for such use. Trap {"Error: $_"; Break;} $D = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() $Domain = [ADSI]"LDAP://$D" $Searcher = New-Object System.DirectoryServices.DirectorySearcher $Searcher.PageSize = 200 $Searcher.SearchScope = "subtree" # Switch this to search for computers or users $Searcher.Filter = "(&(objectCategory=computer))" # $Searcher.Filter = "(&(objectCategory=user))" $Searcher.PropertiesToLoad.Add("distinguishedName") > $Null $Searcher.PropertiesToLoad.Add("lastLogon") > $Null # Create hash table of users and their last logon dates. $arrUsers = @{} # Enumerate all Domain Controllers. ForEach ($DC In $D.DomainControllers) { $Server = $DC.Name $Searcher.SearchRoot = "LDAP://$Server/" + $Domain.distinguishedName $Results = $Searcher.FindAll() ForEach ($Result In $Results) { $DN = $Result.Properties.Item("distinguishedName") $LL = $Result.Properties.Item("lastLogon") If ($LL.Count -eq 0) { $Last = [DateTime]0 } Else { $Last = [DateTime]$LL.Item(0) } If ($Last -eq 0) { $LastLogon = $Last.AddYears(1600) } Else { $LastLogon = $Last.AddYears(1600).ToLocalTime() } If ($arrUsers.ContainsKey("$DN")) { If ($LastLogon -gt $arrUsers["$DN"]) { $arrUsers["$DN"] = $LastLogon } } Else { $arrUsers.Add("$DN", $LastLogon) } } } # Output latest last logon date for each user. $Users = $arrUsers.Keys ForEach ($DN In $Users) { $Date = $arrUsers["$DN"] If ($Date -eq "01/01/1601 00:00:00") {$Date = "1/1/1900 12:00:00"} $DN = [regex]::Match($DN,'CN=([^,]+)').Groups[1].Value "`"$DN`",$Date" } 

上次login信息在域控制器之间自动复制。

如果它不在您的环境中,那么复制被破坏,并且检索用户的上次login时间是您的问题的最小问题,因为您的AD实施已经无法挽回(或者即将在您的域控制器开始彼此墓碑时)。

顺便说一句, 这似乎最后login时间戳这篇文章可能是你感兴趣的 。

每当用户或计算机login到域时,lastLogontimeStamp属性都不会更新。 更新值的决定基于当前date减去(ms-DS-Logon-Time-Sync-Interval属性减去5的随机百分比)的值。 如果结果等于或大于lastLogontimeStamp,则更新属性。 对lastLogontimeStamp的复制没有特别的考虑。 如果属性被更新,它就像任何其他属性更新一样被复制。

就像这个,在Last Logon Attribute上

此属性不会被复制,并在域中的每个域控制器上分别进行维护。 要为用户在域中的上次login获取准确的值,必须从域中的每个域控制器中检索用户的Last-Logon属性。 检索到的最大值是该用户的最后一次login时间。