I need a script which delete the home directory of disabled users after a specific time ( say 120 days) .
For that i have got a script which connects to an OU and deletes all disabled user's home directories . Now i believe i have to modify it based on attributes and vbscript date and time management.
Here are the attributes and values that i found in AD
Account is Diabled True ( for disabled accts)
Useraccountcontrol 512 (enabled users)
Useraccountcontrol 514 (disabled)
DScorePropagationData ( This is showing a date of deprovision which is the exact date of deprovision)
usnChanged xxxxxxx
usnCreated xxxxxx
WhenChanged month/date/year 2:19:50 PM
Now Can we extract the date from whenchanged attribute and then modify the script so that after 120 days of time mentioned in whenchanged the home directory gets deleted?
Any help is greatly appreciated.
##########################
Option Explicit
Dim objOU, objUser, objFSO, strHomeDirectory
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Bind to the OU.
Set objOU = GetObject("LDAP://ou=Domain Users,dc=Testlab,dc=com")
' Filter on user objects.
objOU.Filter = Array("user")
' Enumerate all users.
For Each objUser In objOU
if objuser.useraccountcontrol = 514 then
' Retrieve home directory.
strHomeDirectory = objUser.homeDirectory
' Replace %username% with value of sAMAccountName attribute.
strHomeDirectory = Replace(strHomeDirectory, "%username%", _
objUser.sAMAccountName)
' Delete the folder.
objFSO.DeleteFolder strHomeDirectory
else
wscript.sleep 100
End If
Next
################################################################