This is a short script that will search the local machine for profiles that haven't been used in X number of days (60 default) and deletes them. Uses ShouldProcess to provide verification of profile deletion. Can be run remotely ComputerName parameter. Also allows you to exclude specific profiles matching by SID or localPath name using regex. By default this script will try not to remove the default profile, NetworkService and LocalSystem

 

PowerShell
Edit|Remove
cleanup-userprofiles 
 
Confirm 
Are you sure you want to perform this action? 
Performing the operation "Cleanup-UserProfiles" on target "Remove profile for user 
S-1-5-21-3810522679-75713840-1701520182-1005 from computer . with local path C:\Users\TestUser". 
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y