0

Having an issue with deleting user profiles on server 2008 when they become corrupt, we have successfully done this now by closing a process but it killed the server and forced a restart, not to bad as we are testing this server and only had 2 users on.

Is there any safe/quick way to do this via a script ?

JJJJNR
  • 870
  • 6
  • 20
  • 32

2 Answers2

0

You can do this in Powershell:

get-wmiobject win32_userprofile -filter "localpath='c:\\users\\BadProfile'" -computer MyServer | remove-wmiobject

That should do it for you. Obviously, replace "BadProfile" with the user's username and MyServer with the name of your server. The -computer switch lets you do it remotely if necessary. You can omit that switch if you're working with a local profile.

squillman
  • 37,883
  • 12
  • 92
  • 146
0

ntuser.dat is a registry hive file that contains the registry entries associated with the profile. The kernel itself has the file open; the hive has to unloaded to unlock the file. You can force it to unload with reg unload, though you'll need the SID of the user that owns the profile. There is a related "classes" hive that expands HKEY_CLASSES_ROOT for each profile as well.

reg unload HKEY_USERS\S-1-5-21-1555713158-3015222722-1959872020-2924
reg unload HKEY_USERS\S-1-5-21-1555713158-3015222722-1959872020-2924_Classes

This applies to all versions of Windows since XP and there is something similar in all the previous versions of WinNT as well.

In general, it would be better to let Windows unload the profile itself, by removing the open references to it.

Chris Smith
  • 580
  • 1
  • 4
  • 13