Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: Account Expiration Script - Notify Manager

Reply
Thread Tools Display Modes

Re: Account Expiration Script - Notify Manager

 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      10-18-2008
See my reply in microsoft.public.scripting.vbscript.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"vivah8t" <> wrote in message
news:28dbfd7e-f17f-47bd-91dc-...
> All,
>
> Thanks for any help you can provide. I'm a novice at vbs scripting.
> I've taken parts of existing scripts to create an Account Expiration
> script. The intent is to find all accounts expiring in 14 days and
> send a warning email to the Account's manager. I have all of the data
> pieces of the script working and returning the appropriate data, but
> I'm struggling with the piece for notifying the manager. I'm trying
> to find a way to use the ouser.manager attribute which returns the CN=
> name of the manager to get the manager's email address. I know there
> must be a simple way to do this, but because of my inexperience I've
> run into a brick wall. Below is the script. Right now I have the
> notification piece turned off and just logging to a file.
>
> Thanks,
>
> Roland
>
>
> '################################################# ###########################
> '#
> '# Account Expiration Notice
> '#
> '# This script checks for user accounts that will exire
> '# in a certian number of days and send notification email to the
> manager.
> '#
> '################################################# ###########################
>
> '### VARS ###
> '#
>
> dtToday = Date
>
> '# sScriptLogFile is the path of the log file for this script
> sScriptLogFile = "C:\Scripts\AccountExpirationNotice.log"
>
> '#
> '###
>
> '### Subs
> '#
>
> '---------------------------------------------------------------------------------------------------
> ' The WriteLog function writes a line to the log file and prepends the
> time and date
> '---------------------------------------------------------------------------------------------------
> Function WriteLog(sLogLine)
>
> sFullLogLine = now & " - " & sLogLine
> oScriptLog.WriteLine (sFullLogLine)
>
> End Function
>
> '---------------------------------------------------------------------------------------------------
> ' The SendWrnEmail function sends the warning email that an account is
> going to expire
> '---------------------------------------------------------------------------------------------------
> Function SendWrnEmail(sTo,sDisplayName,sUserName,iDays,dtEx pire)
>
> 'Subject and body for the email
>
> sWrnEmailSubject = "Account Expiration Notice - Temp / Contractor : "
> & oUser.givenname & " " & oUser.sn
> sWrnEmailBody = swrnEmailBody & "XXXXX" & "," & vbCrLf & vbCrLf
> sWrnEmailBody = sWrnEmailBody & oUser.givenname & " " & oUser.sn &
> "'s " & "account will expire in " & iDays & " days." & vbCrLf
> sWrnEmailBody = sWrnEmailBody & "If you would like their access to
> continue, Please submit a helpdesk ticket to EMAILADDRESSHERE and
> state the duration up to 90 days." & vbCrLf & vbCrLf
> sWrnEmailBody = sWrnEmailBody & "Thank You," & vbCrLf
> sWrnEmailBody = sWrnEmailBody & vbCrLf
> sWrnEmailBody = sWrnEmailBody & "IT Tech Support"
>
> Set oCDOSYSMail = WScript.CreateObject("CDO.Message")
> Set oCDOSYSConf = WScript.CreateObject ("CDO.Configuration")
>
> 'SMTP server's name
> oCDOSYSConf.Fields("http://schemas.microsoft.com/cdo/configuration/
> smtpserver") = "MAIL SERVER HERE"
> 'Port used by the SMTP server to send e-mail
> oCDOSYSConf.Fields("http://schemas.microsoft.com/cdo/configuration/
> smtpserverport") = 25
> 'SMTP over the network instead of using the local SMTP service pickup
> directory
> oCDOSYSConf.Fields("http://schemas.microsoft.com/cdo/configuration/
> sendusing") = 2
> 'Time-out duration
> oCDOSYSConf.Fields("http://schemas.microsoft.com/cdo/configuration/
> smtpconnectiontimeout") = 60
> oCDOSYSConf.Fields.Update
>
> 'Setting up e-mail and its configuration
> Set oCDOSYSMail.Configuration = oCDOSYSConf
> oCDOSYSMail.From = "FROM ADDRESS HERE"
> oCDOSYSMail.To = sTo
> oCDOSYSMail.Subject = sWrnEmailSubject
> oCDOSYSMail.TextBody = sWrnEmailBody
>
> 'Send the email
> oCDOSYSMail.Send
>
> 'Close the server mail Object
> Set oCDOSYSMail = Nothing
> Set oCDOSYSConf = Nothing
>
> End Function
>
>
> '---------------------------------------------------------------------------------------------------
> ' The CheckExpiration checks to see if the user's account is going to
> expire soon, if it will then
> ' a notification email will be generated.
> '---------------------------------------------------------------------------------------------------
> Function CheckExpiration()
>
> dtExpDate = oUser.AccountExpirationDate
>
> 'Get Days Until Account Expiration
> iDays = DateDiff("d",dtToday,dtExpDate)
>
>
> If iDays = -14167 Then
>
> Else
>
> If iDays <= 0 Then
>
> sLogMsg = ouser.samaccountname & " --- " & "Is Already Expired"
> Call WriteLog(sLogMsg)
>
> Else
>
> If iDays <= 14 AND > 0 Then
>
> sLogMsg = oUser.Mail & "---" & oUser.samaccountname & " --- " & iDays
> & " --- "
> Call WriteLog(sLogMsg)
> 'Call SendWrnEmail (sTo,sDisplayName,sUserName,iDays,dtExpire)
>
>
>
> End If
> End If
> End Function
>
> '#
> '###
>
> '### Main ###
> '#
>
> Set oFSO = CreateObject("Scripting.FileSystemObject")
>
> 'Let see if the script's log file exists and if so lets open it for
> appending, otherwise create and open
> If oFSO.FileExists(sScriptLogFile) then
> Set oScriptLog = oFSO.OpenTextFile(sScriptLogFile, 8)
> Else
> Set oScriptLog = oFSO.OpenTextFile(sScriptLogFile, 2, True)
> End If
>
> ' Connect to LDAP and get all user accounts
> Set objCommand = CreateObject("ADODB.Command")
> Set objConnection = CreateObject("ADODB.Connection")
> objConnection.Provider = "ADsDSOObject"
> objConnection.Open "Active Directory Provider"
> Set objCommand.ActiveConnection = objConnection
>
> 'Lets get the correct Top level DN for our domain
>
>
> strBase = "LDAP:// TOP LEVEL HERE"
>
> strQuery = "SELECT AdsPath FROM '" & strBase & "' WHERE
> objectCategory='person' and objectClass='user'"
>
> objCommand.CommandText = strQuery
> objCommand.Properties("Page Size") = 100
> objCommand.Properties("Timeout") = 30
> objCommand.Properties("Cache Results") = False
>
> sLogMsg = "Connecting to LDAP"
> Call WriteLog(sLogMsg)
>
> Set objRecordSet = objCommand.Execute
> Do Until objRecordSet.EOF
> sAdsPath = objRecordSet.Fields("AdsPath")
> set oUser = GetObject(sAdsPath)
>
> Call CheckExpiration()
>
> objRecordSet.MoveNext
> err.clear
> Loop
> wScript.Echo "Done!"
> oScriptLog.Close
>
> objConnection.Close
>
> '#
> '###



 
Reply With Quote
 
 
 
Reply

« tasklist | Politics »
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Frequent Account Lockouts after changing account expiration CK Active Directory 2 08-05-2008 11:16 AM
Do you want to own one tool that check and notify your new Email to your MSN account? Bricksoft Windows Live Messenger 4 06-05-2008 02:21 AM
Script to notify about user's certificate expiration BrAtKo Scripting 0 03-07-2008 08:32 AM
AccountExpirationDate Account Expiration script Chris80523 Scripting 3 01-07-2008 09:31 PM
Re: Account Expiration! Jerold Schulman Active Directory 0 06-06-2005 12:55 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59