Last Logon (disable accounts)

D

Danny Phillips

I found the follow script, It is supposed to check the
last login date and if the user has not logon in x number
of weeks disalbe the account.

Can anyone tell me why it is not working







Dim dDate, oUser, oObject, oGroup
Dim iFlags, iDiff, iResult
Const UF_ACCOUNTDISABLE = &H0002

'Point to group containing users to check
Set oGroup = GetObject("WinNT://my domain/Domain Users")
'Enable error trapping

On error resume Next

'for each user object in the group...
For each oObject in oGroup.Members
'ensure the user isn't a computer account!
If (oObject.Class="User") And _
(InStr(oObject.Name, "$") = 0) Then
'retrieve the user object
Set oUser = GetObject(oObject.ADsPath)
'get the last login Date from the domain
'and strip off the time portion
'(just need the date)
dDate = oUser.get("LastLogin")
dDate = Left(dDate,8)
dDate = CDate(dDate)

'calculate how long ago that was in weeks
iDiff = DateDiff("ww", dDate, Now)
'more than six weeks since last login?
If iDiff > 12 Then
'yes - get the user's flags
iFlags = oUser.Get("UserFlags")

'is the account already disabled?
If (iFlags AND UF_ACCOUNTDISABLE) = 0 Then
'no - disable it!
oUser.Put "UseriFlags", iFlags OR
UF_ACCOUNTDISABLE
oUser.SetInfo
End If
End If
End If
Next
Wscript.Echo "All Done!"
 
J

Jerold Schulman

I can't, but tip 7358 in the 'Tips & Tricks' at http://www.jsiinc.com works.


I found the follow script, It is supposed to check the
last login date and if the user has not logon in x number
of weeks disalbe the account.

Can anyone tell me why it is not working







Dim dDate, oUser, oObject, oGroup
Dim iFlags, iDiff, iResult
Const UF_ACCOUNTDISABLE = &H0002

'Point to group containing users to check
Set oGroup = GetObject("WinNT://my domain/Domain Users")
'Enable error trapping

On error resume Next

'for each user object in the group...
For each oObject in oGroup.Members
'ensure the user isn't a computer account!
If (oObject.Class="User") And _
(InStr(oObject.Name, "$") = 0) Then
'retrieve the user object
Set oUser = GetObject(oObject.ADsPath)
'get the last login Date from the domain
'and strip off the time portion
'(just need the date)
dDate = oUser.get("LastLogin")
dDate = Left(dDate,8)
dDate = CDate(dDate)

'calculate how long ago that was in weeks
iDiff = DateDiff("ww", dDate, Now)
'more than six weeks since last login?
If iDiff > 12 Then
'yes - get the user's flags
iFlags = oUser.Get("UserFlags")

'is the account already disabled?
If (iFlags AND UF_ACCOUNTDISABLE) = 0 Then
'no - disable it!
oUser.Put "UseriFlags", iFlags OR
UF_ACCOUNTDISABLE
oUser.SetInfo
End If
End If
End If
Next
Wscript.Echo "All Done!"


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VB Script for User Info 1

Top