# Remove Stale Profiles Windows 10

**URL:** <https://forums.powershell.org/t/remove-stale-profiles-windows-10/12446>\
**Category:** PowerShell Help\
**Created:** [April 25, 2019, 3:52am UTC](https://forums.powershell.org/t/remove-stale-profiles-windows-10/12446 "2019-04-25T03:52:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![simbrook](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@simbrook](https://forums.powershell.org/u/simbrook)\
**Post date:** [April 25, 2019, 3:52am UTC](https://forums.powershell.org/t/remove-stale-profiles-windows-10/12446/1 "2019-04-25T03:52:30Z")

</div>

I am trying to automate the removal of old profiles from shared windows 10 machines on our domain. I have the below script that can run as a Scheduled task

&nbsp;

```
Get-CimInstance win32_userprofile -Verbose | 
Where {(!$_.Special) -And ($_.LastUseTime -lt $(Get-Date).Date.AddDays(-30))} |
Remove-CimInstance -Verbose -WhatIf
```

But it would appear that something is modifying the usrclass.dat so the LastUseTime is not reporting correctly. i.e. a user may of not logged onto the machine for over a month but their usrclass.dat file was modified yesterday. Any ideas what other properties / files I can use to determine if a user has not logged in for 30 days ?

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [May 7, 2019, 6:35pm UTC](https://forums.powershell.org/t/remove-stale-profiles-windows-10/12446/2 "2019-05-07T18:35:20Z")

</div>

You don’ stay what OS you are running, and because even this effort may run into this issue …

> Stale user profile folders are not deleted completely in Windows 7 or in Windows Server 2008 R2 https://support.microsoft.com/en-gb/help/2661663/stale-user-profile-folders-are-not-deleted-completely-in-windows-7-or

See also …

> https://learn-powershell.net/2011/01/27/use-powershell-to-remove-local-profiles
> 
> How to delete user profiles older than a specified number of days in Windows  
> This PowerShell script sample shows how to delete user profiles older than a specified number of days.
> 
> > **[Browse code samples](https://learn.microsoft.com/en-us/samples/browse/?redirectedfrom=TechNet-Gallery)**
> >
> > Get started with Microsoft developer tools and technologies. Explore our samples and discover the things you can build.

---

<div class="post-metadata">

**Author:** ![simbrook](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@simbrook](https://forums.powershell.org/u/simbrook)\
**Post date:** [May 8, 2019, 1:30am UTC](https://forums.powershell.org/t/remove-stale-profiles-windows-10/12446/3 "2019-05-08T01:30:12Z")

</div>

Hi Postanote it is Windows 10 (1703) "I am trying to automate the removal of old profiles from shared **windows 10 machines** on our domain. "

That script uses the lastusetime (same as what I was using) see sample below, and this can get changed by symantec running even when that particular user has not logged in.

[pre]$UserProfileLists = Get-WmiObject -Class Win32\_UserProfile | Select-Object @{Expression={$_.\_\_SERVER};Label=“ComputerName”},`  
LocalPath,@{Expression={$_.ConvertToDateTime($_.LastUseTime)};Label=“LastUseTime”} `  
| Where{$_.LocalPath -notlike “_$env:SystemRoot_”}[/pre]

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [May 8, 2019, 6:19am UTC](https://forums.powershell.org/t/remove-stale-profiles-windows-10/12446/4 "2019-05-08T06:19:26Z")

</div>

I just delete them all overnight. There’s a group policy that deletes them too. Or shared pc mode.

---

<div class="post-metadata">

**Author:** ![simbrook](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@simbrook](https://forums.powershell.org/u/simbrook)\
**Post date:** [May 8, 2019, 7:54am UTC](https://forums.powershell.org/t/remove-stale-profiles-windows-10/12446/5 "2019-05-08T07:54:39Z")

</div>

Unfortunately as the usrclass.dat and/or NTUser.dat last access time gets modified by Sep / windows update the Group policy is not working in our env. windows 10 2008 SP2 AD, so the only way I can get the GP to work is to run a script that modifies the last used date of the NT User.dat and I feel this is a bit of a cludge

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:32pm UTC](https://forums.powershell.org/t/remove-stale-profiles-windows-10/12446/6 "2024-05-16T20:32:49Z")

</div>

Closed on May 16, 2024, 8:32pm UTC


