Home Folder – Archiving Disabled Users

Here is aPowerShell script to archive all users within an organisational unit (Disabled Users) to a network path.

Prerequisite is to grant your Administrator account with ownership/full control permissions to home folders in question prior move.

If this condition is not met, then original home folders will remain with remnant data which was inaccessible.

$users = Get-AdUser -SearchBase "OU=Disabled Users,OU=CompanyName,DC=Domain,DC=Local" -Filter *
Foreach ($user in $users)
  $username = $user.SAMAccountName
  $name = $user.name
  $oldhome = "\\Domain.Local\DFS\Users\$username\"
  if(!(Test-Path "\\ArchiveServer\Archive$\$name\Home\")) { MD "\\ArchiveServer\Archive$\$name\Home\"}
  $newhome = "\\ArchiveServer\Archive$\$name\Home\"
  #echo $home
  #echo $destination
  Move-Item -path $oldhome -destination $newhome -Exclude "*RECYCLE.BIN*" -force -ErrorAction ignore