Home Folder – Compare folders against current domain users

Here is a PowerShell script which probes network home folders with users against the domain.

Helpful in order to determine which home folders no longer reference current user accounts and which can safely be removed/archived.

$folders = gci "\\Domain.Local\DFS\Users"
#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"
      Write-Host "THIS PERSON NO LONGER EXISTS: $folder"
      #Remove-Item $folder -Force -Recurse
    }#end if
  }#end foreach