A.D. Group Policy "Delete user profiles older than a specified number days on system restart ” not working

Group policy for deleting old user profiles not working in Windows.

We implemented the Active Directory Group Policy:
“Delete user profiles older than a specified number days on system restart ” to clear old profiles older than 30 days from the PC.

Unfortunately it doesn’t work, nothing gets deleted.

I tracked this down to the setting it looks at for each profile: the “LastUseTime”.
Something was changing the LastUseTime in NTUSER.DAT to today’s date for every user on the computer. Could be something in Windows or maybe our antivirus. Anyhow, it stopped the policy from working.

You can check this with the PowerShell script:
Get-WMIObject -class Win32_UserProfile | Where {(!$_.Special) -and ($_.ConvertToDateTime($_.LastUseTime) -lt (Get-Date).AddDays(-30))}

(Thanks to Charlie Smith on Spiceworks for this)
https://community.spiceworks.com/how_to/124316-delete-user-profiles-with-powershell

Instead, use  the “LastDownloadTime” to check the date of profile download:
Get-WMIObject -class Win32_UserProfile | Where {(!$_.Special) -and ($_.ConvertToDateTime($_.LastDownloadTime) -lt (Get-Date).AddDays(-30))} | Remove-WmiObject

Now it works!!!! I added a shutdown script Group Policy.

NOTE:- there are sometimes errors running this script because the LastDownloadTime or LastUseTime is sometimes empty. You can ignore this error.

Richard Artes Nov 2017

Comments

Popular posts from this blog

Restore a deleted OneDrive for Business account from Office365: "A site collection with the same Site Id or Path already exists."

Server Manager will not start, error .NET Framework: "This application requires one of the following versions of the .NET Framework:"