Hello there,
You can use Powershell to achieve your requirement.
Get-WMIObject -class Win32_UserProfile | Where {(!$.Special) -and ($.ConvertToDateTime($_.LastUseTime) -lt (Get-Date).AddDays(-5))} | Remove-WmiObject
This will then cause the user profile folder to be deleted, and the corresponding profile list entry in the registry to be removed.
The below registry also does the same job.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
Delete the ProfileList key, then all user profiles will be removed completely.
This can be done rather easily by GPO
Group Policy: How to Automatically Delete User Profiles Older Than Certain Number of Days https://social.technet.microsoft.com/wiki/contents/articles/28647.group-policy-how-to-automatically-delete-user-profiles-older-than-certain-number-of-days.aspx
Hope this resolves your Query !!
--If the reply is helpful, please Upvote and Accept it as an answer–