Last active
May 20, 2016 14:45
-
-
Save gioxx/c71611db976536029c57 to your computer and use it in GitHub Desktop.
PowerShell: Alert mail quando un account viene bloccato in AD. Occorrerà creare (sul Domain Controller, per esempio) un'operazione schedulata che per ogni EVENT ID 4740 scatena l'esecuzione di questo script PS1.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ACTIVE DIRECTORY: Alert mail quando un account utilizza una password errata | |
#------------------------------------------------------------------------------- | |
# Autore: GSolone | |
# Utilizzo: E' necessario schedulare questo script quando si presenta l'evento da monitorare | |
# (nel caso specifico qui di seguito è il 4771) | |
# Info: http://wp.me/pdQ5q-4Rh | |
# Ultima modifica: 28-04-2014 (rev1) | |
# Diff: rev1- incluso l'if che permette di procedere con l'invio mail solo se l'account utente | |
# che ha usato una password errata è quello specificato nella variabile AccountMonitor | |
#------------------------------------------------------------------------------- | |
# RAPIDO PROMEMORIA: | |
# -InstanceID 4740: account bloccato | |
# -InstanceID 4771: password errata | |
#-------------------------------------------# | |
# SPECIFICARE L'ACCOUNT DA MONITORARE: # | |
$AccountMonitor = 'UTENTEDISERVIZIO' | |
#-------------------------------------------# | |
Import-Module ActiveDirectory | |
$EventDetails = Get-EventLog -LogName Security -InstanceID 4771 -Newest 1 | Where-Object { $_.message -match $AccountMonitor } | |
$LockedAccount = $($EventDetails.ReplacementStrings[0]) | |
if ($AccountMonitor -eq $LockedAccount) { | |
$EventDetailsTime = $EventDetails.TimeGenerated | |
$EventDetailsMessage = $EventDetails.Message | |
$messageParameters = @{ | |
Subject = "Attenzione: Accesso negato per $LockedAccount" | |
Body = "Qualcuno sta utilizzando una password sbagliata per l'account $LockedAccount (ultimo tentativo il $EventDetailsTime).`n`nDettagli evento:`n`n$EventDetailsMessage" | |
From = "root@localhost.tld" | |
To = "mio.account@azienda.tld" | |
SmtpServer = "smtp.azienda.tld" | |
} | |
Send-MailMessage @messageParameters | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment