Folder redirection and deleting old folders from server


  • Question for other admins using folder redirection GPO.  My environment has about 30,000 on any given day we might have 100-300 new users and the same amount of deletions. 

    The question is how do you go about deleting old folders from your server when users accounts get deleted and keep everything nice and clean. 

    Thanks for everyone input.

    Thursday, January 8, 2015 2:19 PM

All replies

  • I think you mean the home folder? If so see my comment.

    Find attached the script you can use for deleting home folder for deleted AD users.

    Edit "c:\personal\home" matching to your environment. This is the path to the home folders!

    @echo off
    rem Query AD for home folder names

    rem settings
    set USERHOMEDIR=c:\personal\Home
    set USERLIST=%TEMP%\userlist.txt

    rem main

    echo Create Userlist

    for /f %%n in ('dir %USERHOMEDIR% /B /A:D') do (
    echo check AD for useraccount: %%n
    echo delete folder if not found in AD!
    dsquery user -samid %%n | find "CN" & IF ERRORLEVEL = 1 Echo %%n >>.\NotFoundInAD_%date%_%time:~0,2%-%time:~3,2%-%time:~6,2%.txt & rd /s /q %userhomedir%\%%n
    echo done

    goto END

    echo FINITO

    Kind regards,


    This posting is provided 'AS IS' with no warranties or guarantees and confers no rights.

    "If this thread answered your question, please click on "Mark as Answer"

    • Edited by Tim Buntrock Thursday, January 8, 2015 3:24 PM
    • Proposed as answer by Tim Buntrock Wednesday, October 18, 2017 8:27 AM
    Thursday, January 8, 2015 3:21 PM