How to Remove Home Folder Mapping for all AD Users

With so many businesses adopting Microsoft Office 365 or Google Apps for Work, users are now able to put more of their files in the cloud - thus replacing on-site server storage and user home directories. The below Powershell script will remove all user home folder mappings in Active Directory:

Get-AdUser -Filter * -Properties * | Foreach {
   Write-Host "- " $_.Name
   if ($_.HomeDrive -ne $null) {
    Write-Host -NoNewline "|-  Current home:" $_.HomeDrive "->" $_.HomeDirectory": removing... "
    Set-AdUser -Identity $_.DistinguishedName -HomeDirectory $null -HomeDrive $null
    Write-Host "Done."
   }
}

Source: Glenn Matthys

comments powered by Disqus