top of page
  • Writer's pictureChris Keim

How to Archive Terminated Users' Redirected Folders

Updated: Nov 2, 2020



If you have an Active Directory (AD) Organization Unit (OU) with all your terminated users and you want to move their redirected folders to another location to save on space, this script will automate this process.


Script Features

  • Moves terminated users' redirected folders to an archive location.

Script Prerequisites

  • Before doing anything, backup your data.

  • Test the script in your environment and verify the results prior to running the scrip on your production data.

  • The separated users must be in a single Active Directory (AD) Organizational Unit (OU), no sub-OUs.

  • The path to the AD OU that holds the terminated users (e.g. ou=Separated,dc=company,dc=com).

  • The root of the redirected folders path (e.g. G:\Users).

  • The destination directory for the terminated users' redirected folders (e.g. D:\TerminatedUsers).

  • The script relies on Robocopy to move files and folders.

  • The PowerShell session must be run as an administrator.

  • The PowerShell AD module must be installed as the script calls on Get-ADUser.

Script Disclaimer


Run this script at your own risk. But, don’t be too scared as I have run this in many production environments with no issues.


Script How To

  1. Download and place the script in a directory of your choosing. It is recommended to run this script where the data resides.

  2. Open PowerShell as an administrator.

  3. Since this is a function, you must dot source it by entering ". .\move-terminatedusersfolders.ps1" (without the quotes).

  4. Then type Move-TerminatedUsersFolders. This will prompt you for the OU, which you must supply in the format under script pre-requisites. Then it will prompt you for the redirected folder root directory and destination directory. The script will ask you to confirm the information before proceeding.

  5. One log file will be created for script actions in the same directory of the script.

  6. For each user that is moved, a robocopy log file is generated.

Script





149 views0 comments
bottom of page