WIN-008 · Script
User Profile Cleanup
Finds and optionally removes local user profiles that have not been used in a set number of days.
What it does
Useful on shared devices such as labs, libraries, and front desks. Determines the last time each profile was used from the profile registry (most reliable), falling back to other timestamps when needed. Skips system profiles, loaded profiles, and any users you exclude. Report mode (default) changes nothing. Remove mode deletes the profile the same way Windows does, which also removes the profile folder and its registry entry.
Requirements
Windows PowerShell 5.1+, run as SYSTEM or local admin
How to run it
- Run as: SYSTEM or a local administrator
- Run from: any RMM or MDM, Intune, a Group Policy startup script, a scheduled task, or an elevated PowerShell window
- Script type: PowerShell, 64-bit
- User interaction: none; the script never prompts
- Timeout: 10 minutes (30 for Windows Update installs)
Settings
| Name | What it does | Options | Default |
|---|---|---|---|
| Mode | Report (default) or Remove. | Report, Remove | Report |
| InactiveDays | Profiles unused for more than this many days are selected. Default 90. | 90 | |
| ExcludeUsers | Usernames to always keep, for example "admin" or "itsupport". | (none) |
Exit codes
- 0 = nothing to do / removal succeeded, 1 = stale profiles found (Report) or removal errors, 2 = script error
Testing steps
- Run it first with the mode set to Report on one test device. Nothing is changed in that mode.
- Read the log and confirm the planned changes are what you expect.
- Run your chosen settings on the same test target and confirm the result.
- Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
- Roll out to a small group next, then everyone.
Rollback steps
Report mode changes nothing. Remove mode permanently deletes old profiles and their files. Restore from your backup if needed. Start with Report mode and a high day count.
Version and change log
| Version | Date | Changes |
|---|---|---|
| 1.0.0 | November 2026 | First release. |