be notified by email when an active directory user account is locked out, this powershell script will grab the most recent lockout event and send you an email notification. requires a windows 2008+ domain controller and an email system accepting a relay from the dc.
$event = get-eventlog -logname security -instanceid 4740 -newest 1 $mailbody= $event.message + "
r`t" + $event.timegenerated $mailsubject= "user account locked out" $smtpclient = new-object system.net.mail.smtpclient $smtpclient.host = "exchsvr.domain.local" $mailmessage = new-object system.net.mail.mailmessage $mailmessage.from = "email@example.com" $mailmessage.to.add("firstname.lastname@example.org") $mailmessage.isbodyhtml = 0 $mailmessage.subject = $mailsubject $mailmessage.body = $mailbody $smtpclient.send($mailmessage)
create a new task in task scheduler to run on an event trigger with event id 4740. create a new action to ‘start a program’ and add this path under program/script:
c:\windows\system32\windowspowershell\v1.0\powershell.exe -file c:\scripts\acc_lockout.ps1 when you click ok, task scheduler is smart enough to break the argument up and add them to the correct field.
before you set it and forget it, go to the general tab and select ‘run whether user is logged on or not’ and use an account with the proper rights, like your common dedicated service account.
if you’re getting the error:
“file c:\scripts\acc_lockout.ps1 cannot be loaded because the execution of scripts is disabled on this system. please see “get-help about_signing” for more details.”, then you will need to turn off the execution policy with:
set-executionpolicy -0 you should see an email in the following format- a user account was locked out. subject: security id: s-1-5-18 account name: domaincontroller$ account domain: domainname logon id: 0x3e7 account that was locked out: security id: s-1-5-21-2388021981-560130107-590547658-1106 account name: adminuser1 additional information: caller computer name: serverhost1 11/08/2012 14:12:29
when you're a little too careless about virtualizing your domain controllers, cloning, migrating, backing up and restoring, returning from vacation… Read More
systemd is new service manager for linux. it's a replacement for all previous init systems (sysv/sysvinit & ubuntu's upstart) and… Read More