Home Folder – Compare folders against current domain users V2

This is version 2 to below Powershell script to query parent directory containing user home folders or profiles.

Especially helpful for housekeeping deprecated RDS & Citrix profiles, maximising disk space on your profile file server.


  • Added error handling with try/catch.
  • Added input for directory path.
  • Added color for deprecated profiles.
  • Removed unnecessary reporting of valid profiles.
$moduleName = Get-Module -List ActiveDirectory
 Write-Host "Can't locate ActiveDirectory PowerShell module. Try running script from a server with AD/Domain role." -foregroundcolor "magenta"

$folders = Read-Host -Prompt "Enter UNC path containing profiles. (Eg. \\ServerName\D$\CitrixProfiles)"
$folders = gci $folders
#This is the root path containing home folders.

foreach ($folder in $folders)

$username1 = $null
 $username1 = (get-aduser $folder.name).Name
 if ($username1 -ne $null)
 #Write-Host "$folder This user exists, so don't delete the home folder"
 }#End Try
 Write-Host "THIS PERSON NO LONGER EXISTS: $folder" -foregroundcolor "magenta"
 #Remove-Item $folder.fullname -Force -Recurse
 #Un-Comment above line if you wish to delete profiles following confirmation of non-existence.
 }#End foreach