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!"
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!"