PoshCode Archive  Artifact [05240fa004]

Artifact 05240fa004f122da7d0684b9b3568b7e1cb14b095c25d9ec12668cb129a6eead:

  • File Locked-accounts-alerter.ps1 — part of check-in [1acc262ee5] at 2018-06-10 13:29:25 on branch trunk — Its about time I added something to this site instead of leaching all of the great scripts. (user: Ty Lopes size: 3004)

# encoding: utf-8
# api: powershell
# title: Locked accounts alerter
# description: Its about time I added something to this site instead of leaching all of the great scripts.
# version: 0.1
# type: script
# author: Ty Lopes
# license: CC0
# x-poshcode-id: 3686
# x-archived: 2016-11-16T09:38:54
# x-published: 2012-10-10T15:35:00
#
# #Created By: Ty Lopes
# #Sept 2012
# #Sript to be run by a scheduled task that monitors for a specific event ID (in this case account locked)
# #The sript then reads the last correstponding event ID and emails the details
# #I could only get this alert to work properly by using this method… There may be something easier/better for you out there.
# #This process will have to be followed for each domain controller (since any DC may lock the account and others may not trigger the event id
# #We have two DC’s so this worked well for us
# #The account the task runs under obviously needs rights to read the event logs on the DC
# #Setup the Task
# #Create a scheduled task
# #On the general tab, Run Wether user is logged on or not and Run with highest priveledges
# #On the triggers tab, Select NEW, “On an Event”.
# #Populate 
# #log: Security
# #Source: Microsoft-Windows-security-auditing
# #Event ID: 4740
# #Under Actions: New: STart a program:
# #Program: powershell.exe
# #Arguments: -command “& ‘C:\scripts\accountLocked.ps1’ “  (pointing to wherever your script lives)
#
#Created By: Ty Lopes
#Sept 2012
#Sript to be run by a scheduled task that monitors for a specific event ID (in this case account locked)
#The sript then reads the last correstponding event ID and emails the details
#I could only get this alert to work properly by using this method... There may be something easier/better for you out there.
#This process will have to be followed for each domain controller (since any DC may lock the account and others may not trigger the event id
#We have two DC's so this worked well for us
#The account the task runs under obviously needs rights to read the event logs on the DC

#Setup the Task
#Create a scheduled task
#On the general tab, Run Wether user is logged on or not and Run with highest priveledges
#On the triggers tab, Select NEW, "On an Event".
#Populate 
	#log: Security
	#Source: Microsoft-Windows-security-auditing
	#Event ID: 4740

#Under Actions: New: STart a program:
#Program: powershell.exe
#Arguments: -command "& 'C:\scripts\accountLocked.ps1' "  (pointing to wherever your script lives)


#Script Start

	start-sleep 10

	$dcName = "DomainController"
	$eventID = "4740"
	$mailServer = "smtpServer"
	$eSubject = "AD account locked"
	$emailAddy = "user@domain.com"

	$lockEvent = get-eventlog -logname security -computername $dcName -instanceid $eventID -newest 1

	$emailBody = $lockEvent.message
	Send-MailMessage From lockedAccount@domain.com To $emailAddy Subject $eSubject Body $emailBody SmtpServer $mailServer

#Script end