Technology, Cloud computing and Automation…

New script: Find Orphaned Home Folders

I recently uploaded a new script, Get-OrphanHomeFolder.ps1 to the TechNet Gallery. The script is designed to get a list of all folders in a path and for each of those folders it will query AD to verify if there is a matching Sam account. If this property is not found the script considers this to be an orphaned home folder. If the -FolderSize property is specified the script will retrieve the size of the orphaned folder and display the results as an array of objects.

This portion of the script will grab the folder name and query AD for a matching samaccountname, to do this I utilize the [adsisearcher] accelerator so there is no dependency on the AD Cmdlets in this script:

If a matching account is not found the script will display the error, in this case the ‘Account does not exist and has a home folder‘ message and the full path to the folder. This information is stored in a hashtable. The code for that look like this:

54
55
56
57

$HashProps=@{'Error'='Account does not exist and has a home folder''FullPath'=$_.FullName
}

$HashProps = @{
'Error' = 'Account does not exist and has a home folder'
'FullPath' = $_.FullName
}

The information gathered in this hash table is then used to build a custom PowerShell object with the hash table as its properties:

65

New-Object-TypeName PSCustomObject -Property $HashProps

New-Object -TypeName PSCustomObject -Property $HashProps

For more information about this script or any of the other contributions, drop me a line and I will be happy to discuss this further.

Post navigation

6 thoughts on “New script: Find Orphaned Home Folders”

Excellent script! I have some wishes:
* Some of my user profile folders are named %username%.v2 and %username%.domain, would be great if the script would work on these as well
* Unfortunatly, some of our systems also have folders within the main userfolder – If I could provide a list of folders to exclude to the script that would be neat. Same problem if you want to move the orphaned folders to a folder within the users-folder.

Hi Jaap, love the script it is exactly what we are looking for except our home folders are also used for redirected folders and profiles. I’ve spend 2 days trying to modify your script to takeownership and propagate Admins across all files and folders on the entire orphaned users path, where we can then move the entire users folder without errors on files/folders that we have no access.

Any tips? I can get the logic to work, but it is just not forcing the ownership of files/folders that we have no access too.