查询AD 账号锁定

发布时间 2023-03-24 17:01:56作者: vmsky

查询账号:

搜索安全日志,寻找锁定源

点击查看代码
$properties = @(
'TimeCreated',
@{n='Account Name';e={$_.Properties[0].Value}},
@{n='Caller Computer Name';e={$_.Properties[1].Value}}
)
$LockoutSource = Get-WinEvent -MaxEvents 1 -FilterHashTable @{LogName='Security'; ID=4740} | Select $properties | Format-Table -AutoSize -Wrap | Out-String
#SMTP发信验证,$anonUser 为发邮箱账户,anonPass 为发邮件账户密码
$AnonUser="账号"
$AonPass=ConvertTo-SecureString "XwETL5)8u%u2dL$" -AsPlainText -Force
$AonCred=New-Object System.Management.Automation.PSCredential($AnonUser,$AonPass)
#仅通知合肥EUS
Send-Mailmessage -from  "发件人邮箱账号" -to "收件人" -Body $LockoutSource -Subject "域账号锁定通知" -smtpserver 邮箱服务器  -Credential $AonCred -Encoding ([System.Text.Encoding]::UTF8)