Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Delete Home directory for disabled users question

$
0
0

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

################################################################


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>