As IT Engineer I am responsible for maintaining servers that have a limited disk space available. One of my tasks is to remove temporary files from user profiles on terminal servers.
Since I am in favor of automating anything that I need to do multiple times, I decided to create a PowerShell script to clear the Temp folder under each profile on the terminal servers, as well as search for specific extensions that other third party applications create for temporary files.
- Find all the directories under the users profile folder
- Gets all the files under each profile that matches the extensions supplied and deletes the files
- Gets all the files and folders under the profile’s Temp directory and deletes the files and folders
- The Force option is not used for deleting files. Since certain files may still be in use or may be marked as system files and shouldn’t be deleted.
This script has the following requirements:
- The folder where the user profiles are located
- [Optional] The extensions that needs to be removed
- Read-Write access to all profile folders
- The script must run as Administrator
Clean-Profiles.ps1 -ProfilesPath -Extensions
D:\PowerShellScripts\Clean-Profiles.ps1 -ProfilesPath “C:\Users” -Extensions “*.tmp”,”*.log”