Deleting User Profiles – Correctly
Commenter Steven asked in response to my article on how not to delete local user profiles for the correct way to script the deletion of user profiles. Here is how. For completeness sake I start with the manual method.
Deleting Profiles Manually
-
Open the control panel applet “System Properties” and navigate to the tab “Advanced”. I know of the following shortcuts for this often needed dialog box:
- Press Win+R to open the run dialog box. Type
SystemPropertiesAdvanced.exe
- Press Win+R to open the run dialog box. Type
control sysdm.cpl,,3
and press enter. Note there must not be entered a space in front of the commas. - Press Win+Break
- Press Win+R to open the run dialog box. Type
- Click on the settings button in the user profiles section.
- In the dialog that appears, choose the appropriate user profile and click on delete. Note: you must be an administrator for the delete button to even show up. And: you cannot delete your own profile.
Deleting Profiles Automatically
Microsoft’s delprof
utility can be used to delete all local(ly cached) user profiles. Optionally, only profiles not used for a specified number of days are deleted. Another option (/r) restricts the deletion to locally cached roaming profiles.
Please note: By default, delprof
deletes all profiles! It does, however, ask for confirmation before each delete, unless the parameter /q is specified.
Usage examples:
Delete all cached copies of roaming profiles on the local machine:
delprof /q /i /r
Delete all profiles not used for 10 days on computer server:
delprof /q /i /c:\\server /d:10
Microsoft’s Delprof does not work on operating systems newer than Windows XP/2003. It is not compatible with Windows 7 and 2008 R2. To fill the void I have written a syntax-compatible successor called Delprof2 which works on all versions of Windows and is even more powerful. Find more information and download Delprof2 here.
References
13 Comments
Hello!
I’ve got a profile with status “temprorary” in the sysdm-windows and want to delete it, so that the user gets his “normal” profile back which is stored on a share. With delprof the profile isn’t listed, so who would I delete this file correctly?
When I log in with this user, the profile is loaded into c:\documents and settings\temp…
Thanks!
Udo
Solved – I’ve deleted the reg-structure in HKEY_Users for this user, so I could delete the TEMP-profile in C:\documents and settings. After a re-login the old profile was used.
Udo
From an earlier post:
“Whatever the reason, once you got a temporary profile the SID.bak key lingers in the registry. It needs to be deleted to get back to normal profile behavior.” (Applies to Vista/2008)
Good to hear the problem is solved ;-)
On my site, I do have a better version of DelProf.exe and it is script based to it easy modify.
Joe
http://www.theshonkproject.com/index.php?option=com_content&task=view&id=50&Itemid=1
Also note: Users should be running UPHClean… DO NOT DELETE a profile that is LOAD or has handles associated to it.
Joe,
your script looks impressive! Thanks for pointing me to it.
Hi Klein, I regularly read you Blog and I can finally contribute something.
Just a little note, we had been using DelProf.exe on Windows 2008 servers and Vista machines. We are setup with Roaming Profiles and folder Redirection, Delprof gets ride of the user profile in the registry and c:\users but it fails to remove any cached data used by the offline files (Stored in c: Windows\CSC)
The result would be that after removing a profile with Delprof and logging back on with the roaming profile, the Redirected Folders would fail to find the correct network path, using the local cached data in c:\Windows\CSC and at this point the only solution was to add the following registry entry Reg \\%TargetCmp%\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Csc\Parameters /v FormatDatabase /d1 /t REG_DWORD /f in order to flush the Off Line cache at Reboot.
After searching for a while I found that in Vista/2008 the only “correct” way to delete profiles by script is the use the WMI Win32_UserProfile. class
For example we now use the following script the delete roaming profiles remotely :
TITLE %~nx0
@Echo on
cls
@echo .
Set /p TargetCmp=Enter computername on which we will delete all the roaming profiles:
for /f “tokens=1,2″ %%a in (‘wmic /node:”%TargetCmp%” path win32_UserProfile get RoamingConfigured^,Sid^|find “TRUE”‘) do (
echo %%a echo %%b
wmic /node:”%TargetCmp%” path win32_UserProfile where Sid=”%%b” Delete
)
Pause
Exit
Indeed, the client-side cache (CSC) also needs to be cleaned up.
Thanks for contributing the script!
Delprof2 worked quite well. So well in fact that it delete all the files within the Profiles that were not deleted because they were newer than 30 days. I’m lucky I didn’t hit any machines that I could be fired for.
I really need a solution for this. I have over a 1000 desktops and some can get up to 500 profiles on them. I have tried the setting in policy editor, which worked great in 7 seven but doesn’t seem to work at all in Windows 10.
OS = Windows 10 1809 Enterprise
Example:
Delprof2.exe /d:30 /u /i /ed:Localadmin
Any help would be appreciated.
It doesn’t work on Windows 10 (1903 anymore). Shame as it was brilliant!
Hi guys,
I ran the delprof2.exe on my Windows Server 2016 and worked like a charm, but some SID on ProfileList and ProfileGuid that don’t have a folder on c:\users and still on my registry.
Is there a way to delete these orphan SID?
Thank you.
Hi,
Delprof works amazing deleting the profiles older than “X” days, but one question would like to ask is if i can delete a single/specific profile without specifying the date /days, eg; Delprof2.exe /[email protected]
Hi:
Is there a log after exec DelProf2?The command can not list the user profile when i exec this command with “/l”. My os is win7 enterprise sp1. My user is Administrator.