I have found that deleting home directories has been a pain and I could really use some help. Here are some steps and issues that I have come across:
Attempt to delete a folder:
Remove-Item bug which requires me to use gci and pipe to remove-item
Problem with using gci:
does not gather long file names
Have to use a FileSystemObject to read the long file names to delete them
Files in use, found out I have to remove the share first using wmic (Windows 2008)
takes forever
Favorites, Desktop, etc are read only and cannot be deleted until I change the attribute.
So basically, to delete the home directories, I have to:
Remove the share
Take ownership and use icacls to grant administrator full access
Gather the directory contents and delete them, long file names included
Change the attributes on the Favorites and Desktop etc to be able to delete them.
Has anyone already done this in a successful way? It seems as though I have to use Powershell, maybe DOS or Linux commands to get past the long file names, and DOS to remove the attributes? It seems there must be a better way. I have been struggling with this for a long time and would love some help!
I Use alphafs to get past the long filepath issue.
however, my process does run under a user context that has full control permission on the home folder paths.
as well, there was a relatively recent article about changes in windows, with a registry setting, you can completely get rid of the long filepath issues.
details are here:
@Jeffery Hayes, I use Get-OrphanHomeFolder to find those folders which no longer have an account associated with it. I modified it to also allow me to check if someone is in a group, such has someone who is an alum but should not have a folder any longer. Maybe that can help you too. I create a csv file from this module before I delete anything also. This also gets the foldersize if you wish.
I also use Set-NTFSOwner. I checked out the Get-NTFSOrphanedAccess you mentioned which will provide a nice check for me.
When it comes to deleting files/folders that exceed the character limit, I have been using Robocopy. Mirror an empty directory with the contents of the home directory. That will automatically purge all files.
[quote quote=126173]When it comes to deleting files/folders that exceed the character limit, I have been using Robocopy. Mirror an empty directory with the contents of the home directory. That will automatically purge all files.