Library / Windows endpoint

WIN-008 · Script

User Profile Cleanup

Finds and optionally removes local user profiles that have not been used in a set number of days.

Version 1.0.0Language PowerShellUpdated November 2026

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

NameWhat it doesOptionsDefault
ModeReport (default) or Remove.Report, RemoveReport
InactiveDaysProfiles unused for more than this many days are selected. Default 90.90
ExcludeUsersUsernames 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

  1. Run it first with the mode set to Report on one test device. Nothing is changed in that mode.
  2. Read the log and confirm the planned changes are what you expect.
  3. Run your chosen settings on the same test target and confirm the result.
  4. Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
  5. 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

VersionDateChanges
1.0.0November 2026First release.