If your a twitter head like myself, make sure you follow @scriptingguys. That is the official MS Scripting team which handles everything from basic logon scripts to PowerShell scripting! I grabbed this off of their latest tweet! Don’t forget to follow me on twitter ! @csolarz

This was taken from the scripting forums at the following site..  Microsoft Scripting Center!

Script Code


'  Accountexpires.vbs logon script
'  VBScript

'  The script checks the current user's expriation date in AD and compares it against
'  the predermined settings for notification, definted by the strOptions variables
'  If it determines the user's expiration date matches one of those variables, it then notifies
'  the user via message box upon logon to the network. The user is then required to press 'OK' to continue. 
'  Created by:
'  Jason A Winters
'  Systems Administrator
'  Kandahar, Afghanistan
'  DSN: 421-7378
'  jason.winters@afghan.swa.army.mil
'  1 Feb 2010
'--Script Start---------------------------------------------------------------------------------------------------------------------

Dim objUser, CurrentUser
Dim strMbox, DaysToExpiration,strOption1, strOption2, strOption3, strOption4, strOption5, strOption6

'Bind to the user object using the current user

set objUser = Createobject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)

'set options for number of days to check expiration

stroption1 = 1
strOption2 = 2
strOption3 = 3
strOption4 = 7
strOption5 = 14
strOption6 = 30

'Read Account Expiration Date

on error resume next
dtmAccountExpiration = CurrentUser.AccountExpirationDate 

DaysToExpiration = DateDiff("d", Now, dtmAccountExpiration) - 1

' check to see if account expiration date is blank. if blank, then do nothing

If err.number = -2147467259 Or (datediff("d","01/01/1970",dtmAccountExpiration)<=0) Then 
	'Check to see if expiration date matches one of the options specified at the beginning of the script

	If ((DaysToExpiration = strOption1) or (DaysToExpiration = strOption2) or (DaysToExpiration = strOption3) or (DaysToExpiration = strOption4) or (DaysToExpiration = strOption5) or (DaysToExpiration = strOption6)) Then

 	'change the text below to fit your orginizations needs

		strMbox = MsgBox("You have " & DaysToExpiration &" day(s) until your account expires.",0,"** NOTICE **")

	End if
End If
on error goto 0

Platforms -

Windows Server 2008 R2

Windows Server 2008

Windows Server 2003

Windows 7

Windows Vista

Windows XP

Windows 2000

For online peer support, join The Official Scripting Guys Forum! To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.

Disclaimer The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

« »