I've set a Group Policy to remove user profiles not used for 30 days, they are training machines. This functions and removes them from the user profiles list (see borrowed image) but leaves the registry key and profile folder in C:\Users. A known 'feature' when using GP to remove profiles.

What's the easiest way to clean up these reg keys and old profile folders? Some old profile folders just contain an ntuser.dat file.

Preferred methods are Powershell, bat file or Autohotkey exe (that can be run remotely as Admin using PDQ) or other native Windows function.

PC OS is Win7 or Win10. enter image description here

closed as off-topic by Ramhound, Twisty Impersonator, bertieb, Toto, music2myear Oct 26 '18 at 15:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is not about computer hardware or software, within the scope defined in the help center." – Twisty Impersonator, bertieb, Toto
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    We're not a script writing service, however I have provided an answer that shows the 'usual' steps to completely delete a user profile. Ideally, however, it might be a good idea, if you are running a training environment, to use virtual machines and take snapshots of them once they are prepared, ready for training, and then restore the snapshots when training is complete/ready for the next session. – Kinnectus Oct 26 '18 at 8:03
  • @kinnectus. I did not request any scripts be written only that that is the preferred method. 3rd party software is not to be used. Only Windows scripting or if an AHK file was already available; so the code could be scrutinised. I don't want to reinvent the 'wheel' if I overlooked the obvious, which it seems I haven't. More digging it is then. – Andy Anderson Oct 27 '18 at 13:17

The usual way to completely delete Windows profiles is:

  1. Delete the user's profile folder from C:\Users (manually or scripted)
  2. Using regedit (either manually or scripted) remove the user's registry key from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList. Note you will need to identify the user's SID to ensure the correct profile is removed from registry.

Warning (from Microsoft):

Using Registry Editor incorrectly can cause serious, system-wide problems that may require you to re-install Windows to correct them. Microsoft cannot guarantee that any problems resulting from the use of Registry Editor can be solved. Use this tool at your own risk.

  • That is what I am after automating. I have a 1000+ computers to manage so visiting each one is not practical. – Andy Anderson Oct 26 '18 at 8:06
  • @AndyAnderson Hi Andy. Please see the comment on your question explaining that we aren't a script writing service. However of you write your own script and get stuck in the process that's something this site can help with. – Twisty Impersonator Oct 26 '18 at 11:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.