+ Post New Thread
Results 1 to 7 of 7
Windows Server 2008 R2 Thread, Delete old home directories for removed users. in Technical; Hi, We have lots of folders in our home directory directory that are no longer linked to existing accounts. I've ...
  1. #1

    Join Date
    Nov 2011
    Posts
    611
    Thank Post
    85
    Thanked 21 Times in 19 Posts
    Rep Power
    10

    Delete old home directories for removed users.

    Hi,

    We have lots of folders in our home directory directory that are no longer linked to existing accounts.

    I've tried to find a script but they all seem to be for linux.

    Is there a way/script to delete these.

    The home folder names are identical to their usernames.

    Thanks

  2. #2

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,658
    Thank Post
    858
    Thanked 646 Times in 429 Posts
    Rep Power
    498
    If your Home Folders are based on usernames, then a PowerShell script to read in all the folders to a CSV files, and then run the CSV against all usernames in AD, and delete the folder if $samaccountname doesn't exist

    You'd need to play with the powershell code to compare the folder name and samaccountname...

  3. Thanks to Gatt from:

    dany2010 (16th July 2013)

  4. #3
    linkazoid's Avatar
    Join Date
    May 2007
    Location
    London
    Posts
    645
    Thank Post
    119
    Thanked 89 Times in 73 Posts
    Rep Power
    78
    @dany2010 did you ever solve this. I'm in a similar position now and looking for the same solution.

  5. #4

    Join Date
    Nov 2011
    Posts
    611
    Thank Post
    85
    Thanked 21 Times in 19 Posts
    Rep Power
    10
    Hi Linkazoid

    Did it manually in the end. Had a afternoon free so sat down with a Mc Donalds and clicked away comparing AD with the folders.

  6. #5

    Join Date
    Jul 2014
    Posts
    7
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

  7. Thanks to RobOgan from:

    linkazoid (Today)

  8. #6
    linkazoid's Avatar
    Join Date
    May 2007
    Location
    London
    Posts
    645
    Thank Post
    119
    Thanked 89 Times in 73 Posts
    Rep Power
    78
    Thank you. Not quite sure why I couldn't find it on the internet. Looks to be exactly what we need!

  9. #7
    Sephiroth's Avatar
    Join Date
    Mar 2009
    Location
    The Ninth Circle
    Posts
    103
    Thank Post
    9
    Thanked 20 Times in 20 Posts
    Rep Power
    21
    I know you've already solved this but if anyone is interested, this is the method I would use to do this. It assumes that you have all of your Home Directories in one place (but can be modified with just a couple of extra lines to search within a directory tree) and that your directory names are the same as your Usernames:

    Code:
    $Homes = Get-ChildItem "<path to home drives>"
    Foreach ($HomeDir in $Homes) {
        $Name = $HomeDir.Name
        If (DSQuery User -SAMID $Name) {
            Write-Host "Account Exists for $Name"
        }
        Else {
            Remove-Item $HomeDir -Recurse
            Write-Host "Deleted directory: $Name"
        }
    }

SHARE:
+ Post New Thread

Similar Threads

  1. Home folders for AD users
    By kevrage in forum Mac
    Replies: 0
    Last Post: 13th June 2013, 11:35 AM
  2. cant access home folder for one user
    By One_Minute_Hero in forum General Chat
    Replies: 6
    Last Post: 14th January 2013, 03:44 PM
  3. Replies: 7
    Last Post: 13th June 2012, 02:19 PM
  4. Replies: 3
    Last Post: 15th February 2008, 12:58 PM
  5. Replies: 7
    Last Post: 21st August 2007, 01:11 PM

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (1 members and 1 guests)

  1. Firefox

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •