locked
script to delete Home directory question RRS feed

  • Question

  • What i basically wanted is to write 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


    Monday, March 8, 2010 4:42 PM

Answers

  • Hi,

    As the issue is more related to scripting, I would like to suggest that you initiate a new thread in our official scripting forum for better and accurate answer to the question. The community members and support professionals there are more familiar with scripting and can help you in a more efficient way.

    The Official Scripting Guys Forum!

    http://social.technet.microsoft.com/Forums/en-US/ITCG/threads


    Regards,
    Wilson Jia


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Proposed as answer by bshwjt Tuesday, March 9, 2010 9:17 AM
    • Marked as answer by Wilson Jia Friday, March 12, 2010 8:53 AM
    Tuesday, March 9, 2010 6:10 AM