查找锁定的用户并解锁
Search-ADAccount -Locked | Select Name, LockedOut, LastLogonDate
Get-ADUser -Filter * -Properties * | where{$_.lockedout} | ft name
Get-ADUser -Filter * -Properties * | where{$_.lockedout} | Unlock-ADAccount
账户锁定的事件ID为4740
日志审核是否开启
AD服务器通过命令auditpol /get /category:*查看系统审核策略是否开启
$PDC = Get-ADDomainController -Filter * | Where-Object {$_.OperationMasterRoles -contains “PDCEmulator”}
function GetLockedDetails($events)
{
$ret = $events | Select-Object -Property @(
@{Label = ‘用户名’; Expression = {(Get-ADUser -Identity $_.Properties[2].value).Name}}
@{Label = ‘域账号’; Expression = {$_.Properties[0].Value}}
@{Label = ‘锁定源计算机’; Expression = {$_.Properties[1].Value}}
@{Label = ‘锁定时间’; Expression = {$_.TimeCreated}}
@{Label = ‘域控’; Expression = {$_.MachineName}}
@{Label = ‘事件信息’; Expression = {$_.Message -split “`r” | Select -First 1}}
)
return $ret
}
$LockedOutEvents = Get-WinEvent -ComputerName $PDC.HostName -FilterHashtable @{LogName=’Security’; Id=4740}
$ExportPath = “$env:USERPROFILE\Desktop\$(Get-Date -Format “yyyy-MM-dd-HH-mm”)-lockedinfo.csv”
GetLockedDetails -events $LockedOutEvents | Export-Csv -Path $ExportPath -Encoding UTF8 -NoTypeInformation
导出和导入安全策略
- 导出安全策略:
- 使用
secedit.exe工具导出当前的安全配置。命令示例:secedit /export /cfg C:\security-policy.inf。 - 执行命令后,安全策略将被导出到指定的
.inf文件中。
- 使用
- 导入安全策略:
- 使用相同的
secedit.exe工具将之前导出的安全策略导入到另一个Windows系统。命令示例:secedit /configure /db secedit.sdb /cfg C:\security-policy.inf /overwrite
- 使用相同的
查看域默认密码策略
Get-ADDefaultDomainPasswordPolicy
参考链接:
https://4sysops.com/archives/find-the-source-of-account-lockouts-in-ad
