Delete Unused user Profiles on local machine (PowerShell)

This PowerShell script shows how to delete unused user profiles on local machine.

22233.zip
 
 
 
 
 
3.4 Star
(10)
8,027 times
Add to favorites
Storage
11/27/2013
E-mail Twitter del.icio.us Digg Facebook
  • How to modify $PeriodDays
    2 Posts | Last post October 07, 2015
    • I would like to change the amount of unused days to 30, but when I do that and try to run the PS script the box opens and closes right away. 
      
      Just wondering if there is another location in the script that I need to modify?
    • Under the #setunuseddays comment I found the $PeriodDays and set that to the number of days I desired.
  • See "How Not to Delete a Profile"
    1 Posts | Last post January 26, 2015
    • You should not use this script.  https://www.sepago.com/blog/2008/10/16/deleting-a-local-user-profile-not-as-easy-as-one-might-assume
      
      "...what happens if you simply delete the user profile directory below C:\Users without modifying the registry? The next time the user logs on Windows displays a balloon tip whining that Windows could not load the user profile and that the user was logged on with a temporary profile. Is that bad? Yes! Temporary profiles are a last resort if Windows cannot load the user profile. Upon logoff they are deleted and all data is lost. That certainly is a reason to avoid them."
  • LastAccessTime VS LastWriteTime
    2 Posts | Last post November 14, 2014
    • I have just found this script quite nice except few things:
      I suppose LastAccessTime does not fit here properly. If we perform test run of the script (just in case to check what and why it's going to delete) and it will affect old folders assuming that they were 'accessed'. Thus their LastAccessTime will be changed to current one and during next run they won't be removed
      
      PS: btw I suppose it's not good idea to remove profile folders only. It's necessary to improve script with deleting old profile registry keys
    • MaxymK - I had the same thought about not cleaning up the registry keys! I just updated the code and wrote a blog post about how to integrate that into the script. Feel free to check it out! http://www.t2techgroup.com/vdi-blog/easier-way-clean-user-profiles/