How to Archive Terminated Users' Redirected Folders
Updated: Feb 24
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.
Moves terminated users' redirected folders to an archive location.
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.
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
Download and place the script in a directory of your choosing. It is recommended to run this script where the data resides.
Open PowerShell as an administrator.
Since this is a function, you must dot source it by entering ". .\move-terminatedusersfolders.ps1" (without the quotes).
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.
One log file will be created for script actions in the same directory of the script.
For each user that is moved, a robocopy log file is generated.