How to Remove Home Folder Mapping for all AD Users

5 Sep

How to Remove Home Folder Mapping for all AD Users

https://chrisreinking.com/

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:

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