I have this script and I was wondering how I could make it so that when executed it would only send an email when the account was disabled and not when the account is already disabled. See my plans are to have this ran everyday through a scheduler and i dont want to get an email every day if the account is already disabled. I only want to know when it was disabled if it was previously enabled.
strUserDN = "CN=test,OU=Test Accounts,OU=Security,DC=inc,DC=com"
Set objUser = GetObject("LDAP://" & strUserDN)
objUser.AccountDisabled = True
' Email variables:
strServer = "smtp.inc.com"
strTo = "firstname.lastname@example.org"
strFrom = "AcctControlAdmin@test.com"
strSubject = "Account was disabled."
strBody = "The Account was disabled." & VbCrLf
SendEmail strServer, strTo, strFrom, strSubject, strBody, ""
Sub SendEmail(strServer, strTo, strFrom, strSubject, strBody, strAttachment)
Set objMessage = CreateObject("CDO.Message")
objMessage.To = strTo
objMessage.From = strFrom
objMessage.Subject = strSubject
objMessage.TextBody = strBody
If strAttachment <> "" Then objMessage.AddAttachment strAttachment
'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer
'Server port (typically 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'==End remote SMTP server configuration section==
Set objMessage = Nothing