Hi Guys
I need help . I need to create script that will email user when their user account nearly expiered . At the moment I go the folowing script that I got from a website
'***********************************************
'* Connect to AD *
'***********************************************
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT AdsPath FROM 'LDAP://DC=live,DC=local' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
'***********************************************
'* Search User accounts for accounts that *
'* expire within the date range *
'***********************************************
Do Until objRecordSet.EOF
Set objUser = GetObject(objRecordSet.Fields("AdsPath").Value)
If objUser.AccountExpirationDate > strBeginDate and objUser.AccountExpirationDate < strEndDate Then
Wscript.Echo objUser.DisplayName & " expires soon"
Wscript.Echo objUser.DisplayName & " " & objUser.AccountExpirationDate
End If
objRecordSet.MoveNext
Loop
Wscript.Echo "Done with searching AD"
Hope I hear from you guys soon
ASKER
Sorry for the late response . I been busy and holidays . I put together the script that I attached and the script that you provided . I will test it in several days and then I got back to you . See below for the whole script . Please feel free to have a look at it and change it .
'*************************
'*This script will search for user account that nearly expired and email the user *
'*************************
'*************************
'* Connect to AD *
'*************************
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connec
Set objCommand = CreateObject("ADODB.Comman
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio
objCommand.Properties("Pag
objCommand.Properties("Sea
objCommand.CommandText = _
"SELECT AdsPath FROM 'LDAP://DC=live,DC=local' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
'*************************
'* Search User accounts for accounts that *
'* expire within the date range *
'*************************
Do Until objRecordSet.EOF
Set objUser = GetObject(objRecordSet.Fie
If objUser.AccountExpirationD
SendMail "objUser.EmailAddress", "Account Expiration Warning", "Please contact your administrator"
'Wscript.Echo objUser.DisplayName & " expires soon"
'Wscript.Echo objUser.DisplayName & " " & objUser.AccountExpirationD
End If
objRecordSet.MoveNext
Loop
'*************************
'* Procedure to send email to using the *
'* company smtp address *
'*************************
Sub SendMail(strTo, strSubject, strBody)
Const MAIL_SERVER = "smtp.tns-global.com"
Dim objMail
Set objMail = CreateObject("CDO.Message"
objMail.Subject = strSubject
objMail.From = "account.expiration@yourdo
objMail.To = strTo
objMail.TextBody = strBody
objMail.Configuration.Fiel
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fiel
("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= MAIL_SERVER
objMail.Configuration.Fiel
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
= 25
objMail.Configuration.Fiel
objMail.Send
Set objMail = Nothing
End Sub