Group Policy: Automatically Delete User Profiles Older Than Certain Number of Days Win 10 not working.

P. Amila Mahesh Muthukumarana 26 Reputation points
2021-06-18T07:05:45.63+00:00

Hi

I enabled Computer Configuration\Administrative Templates\System\User Profiles\Delete User Profiles Older Than xxx GPO and apply to Windows 10 PCs.
Dayes set to 90.
Unfortunately, this didn't remove old data folders in C:\user.
I checked the registry HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\System was added the REG_DWORD
I'm using Win 2019 domain and Win 10 client PC's.
Can someone help me to fix this?
The link which I use is https://social.technet.microsoft.com/wiki/contents/articles/28647.group-policy-how-to-automatically-delete-user-profiles-older-than-certain-number-of-days.aspx

Kr,
Amila.

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,443 questions
Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,560 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,080 questions
{count} vote

Accepted answer
  1. Hannah Xiong 6,231 Reputation points
    2021-06-18T09:03:43.997+00:00

    Hello @P. Amila Mahesh Muthukumarana ,

    Thanks for posting here.

    I did the testing in my lab, and below are the findings.

    The group policy was configured as shown below.

    106946-image.png

    106947-image.png

    This policy setting allows an administrator to automatically delete user profiles on system restart that have not been used within a specified number of days. Note: One day is interpreted as 24 hours after a specific user profile was accessed.

    If you enable this policy setting, the User Profile Service will automatically delete on the next system restart all user profiles on the computer that have not been used within the specified number of days.

    So I restarted the system and then checked the folders under C:\Users and User profiles were deleted.

    106978-image.png

    106948-image.png

    Hope it helps. For any question, please post here.

    Best regards,
    Hannah Xiong

    1 person found this answer helpful.

9 additional answers

Sort by: Most helpful
  1. DonnaSmith 131 Reputation points
    2022-11-02T11:37:40.033+00:00

    was there a fix for this - ntuser.dat is getting updated preventing the GPO from working
    Is there a way around this to achieve profile removal?

    1 person found this answer helpful.
    0 comments No comments

  2. Adam No name 6 Reputation points
    2022-11-29T10:47:50.097+00:00

    MS have sat on this problem for years now. Even the third party solution, DelProf2 doesn't work anymore due to NTUSER.DAT and ntuser.ini getting updated outside of user logon.

    The only current way is to copy the timestamp from another (currently) working file: UsrClass.dat using the script below, then your GPO for removing stale profiles, which tests on NTUSER.DAT's timestamp, will work.

    Set the script below to run daily as a Scheduled Task. This will then solve the problem of NTUSER.DAT getting its timestamp updated when patched, etc.

    $ErrorActionPreference = “SilentlyContinue”
    $Report = $Null
    $Path = "C:\Users"
    $ExcludedUsers = "Default", "Public", "Administrator"
    $UserFolders = $Path | Get-ChildItem -Directory -Exclude $ExcludedUsers

    ForEach ($UserFolder in $UserFolders)
    {
    $UserName = $UserFolder.Name
    If (Test-Path “$Path\$UserName\NTUser.dat”)
    {
    $NTUserDat = Get-Item "$Path\$UserName\NTUSER.DAT" -force
    $NTUserDatTimeStamp = $NTUserDat.LastWriteTime
    $UsrClassDat = Get-Item "$Path\$Username\AppData\Local\Microsoft\Windows\UsrClass.dat" -force
    $UserClassTimeStamp = $UsrClassDat.LastWriteTime
    $NTUserDat.LastWriteTime = $UserClassTimeStamp
    Write-Host $UserName $NTUserDatTimeStamp
    Write-Host (Get-item $Path\$UserName\AppData\Local\Microsoft\Windows\UsrClass.dat -Force).LastWriteTime
    $Report = $Report + “$UserNamet$NTUserDatTimeStampr`n”
    $NTUserDat = $Null
    $UsrClassDat = $Null
    }
    }

    1 person found this answer helpful.
    0 comments No comments

  3. Joseph Riling 6 Reputation points
    2022-12-19T18:08:33.113+00:00

    @Adam No name

    Hi there. I appreciate your input. I ran the GPO successfully on a couple of test machines, and it works, kind of.

    After I found your post here I created a PowerShell script with the contents and rebooted. This does not seem to work and fully resolve the issue making the profile deletable.

    Let me know if I am missing something. I am also performing updates on the machines now for good measure.

    Thanks

    Joe

    1 person found this answer helpful.

  4. DonnaSmith 131 Reputation points
    2023-01-04T16:03:57.943+00:00

    Any update on this. I can use the script to update ntuser.dat timestamp with the date from usrclass.dat - this works but the GPO is still not removing any old profiles?