Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have migrated from Windows XP to Windows 7 at a high school and have run into a problem. The computer lab machines can have upwards of 5-10 different people log into the machine each day. As time goes on, the local cache of user accounts fills up the small hard drives we have. We don't have money to upgrade so we need to find a way to delete the profiles monthly.

In the past we have used delprof from microsoft which worked great. The problem is that delprof doesn't work for windows 7. Does anyone have a way to delete a profile from a batch/powershell script? If you simple delete the files, you get an error the next time the user logs in.

Thanks in advance

share|improve this question
    
Could you use a mandatory user profile, so that all changes are deleted when the user logs off, or do you need to retain data? –  CarloBaldini Oct 26 '10 at 19:59

6 Answers 6

up vote 3 down vote accepted

wmic path win32_userprofile where special!=true delete or the VBScript/PowerShell equivalent with the necessary WMI calls. The special parameter is redundant, since it will fail to delete special profiles (default profile, NetworkService, LocalService, etc.). If you log output, it will cut down on noise.

share|improve this answer
    
The real answer is "use WMI" to delete it. I even found a powershell way to do that here: stackoverflow.com/questions/3755741/… I tested this and it works, though now I need to write something up to delete users on a remote machine. –  Doltknuckle Oct 27 '10 at 21:25
    
Understandable. I just think PoS sucks away resources in an unnecessary way. I also cannot be bothered, nor my lazy staff, to sign startup scripts the way we should to keep things secure. Best of luck. –  ajstein Oct 28 '10 at 5:09

How about using the method built into Windows instead of trying to script this? Just create group policy using the following setting.

Policy: Delete user profiles older than a specified number of days on system restart

Category Path: Computer Configuration\Administrative Templates\System\User profiles\

Supported On: At least Microsoft Windows Vista

Registry Key: HKLM\Software\Policies\Microsoft\Windows\System

Value: Cleanupprofiles

This policy setting allows an administrator to automatically delete user profiles on system restart that have not been used within a specified number of days. Note: One day is interpreted as 24 hours after a specific user profile was accessed.

If you enable this policy setting, the User profile Service will automatically delete on the next system restart all user profiles on the computer that have not been used within the specified number of days.

If you disable or do not configure this policy setting, User profile Service will not automatically delete any profiles on the next system restart.

share|improve this answer
    
P.S. This page is a good reference for policies gps.cloudapp.net –  Zoredache Oct 26 '10 at 20:04
    
@Zoredcache I do not like to mark people down, but this does not work, at all. I speak from experience, and that of my co-workers, this garbage fails as if it were meant to do the opposite. A quick search on the internet will lead you to posts like this. –  ajstein Oct 26 '10 at 20:14
1  
I have seen this work, but I believe you when you say that it doesn't work in some places. Still It sure seems like you would want to try using the built-in method before trying a script. –  Zoredache Oct 26 '10 at 20:21
    
I've seen this and can attest to the mixed results of it. One of the main issues is that we don't have an automatic restart policy which seems to be the trigger for the wipe. –  Doltknuckle Oct 27 '10 at 20:51
    
I have never got it to work, and we have hundreds of workstations in a university setting. My co-worker tried using it long before me, and I was blown away at how ineffective it was. Moreover, he found a couple of angry TechNet threads where many frustrated Winboxen admins complained it never worked, hence my stern response. I hope I did not come off too dickish. Also, I heard about the cloudapp thing a few days before from Raymond Chen's blog. Very good suggestion, @Zoredache. I need to recommend this to all my coworkers. –  ajstein Oct 28 '10 at 5:08

With PowerShell, I believe this will work.

$profiles = gwmi -class win32_UserProfile -filter "loaded='false'"
foreach ($prof in $profiles)
{
$prof.psbase.Delete()
}

Haven't tested as don't have Windows 7 or Vista box to work with.

share|improve this answer
1  
Same thing I suggested, but PowerShell is so sexy in the eyes of many, even though I call it PoS. Anyway, this is probably more flexible in the future. –  ajstein Oct 28 '10 at 5:06

I have written an inofficial successor to Delprof creatively called Delprof2. It works on all versions of Windows (XP/Vista/7/2003/2008/2008 R2), is syntax-compatible to the original and even more powerful.

Delprof2 is free to use commercially or otherwise.

More information and download: http://helgeklein.com/free-tools/delprof2-user-profile-deletion-tool/

share|improve this answer
    
I'll have to give that a try and see what happens. Thanks for the tool. –  Doltknuckle Jul 25 '11 at 17:56

Delprof2 of Helge Klein is a wonderful tool for removing user profiles. I tried on Windows 7 and it removed those user profiles settings in registry too. Delprof2 is very simple to use. Merci Helge Klein.

share|improve this answer
    
Please add a link to this tool. –  SvW Oct 29 '12 at 9:20

How many machines are you dealing with? If it's not too many, perhaps it might be feasible to remove the profiles using a script or manually using the system properties panel (see screenshot). Once the system is at a "clean" state, you can use a reboot to restore software to clear out any changes made at a specified time. One such product is Deep Freeze by Faronics.

http://www.faronics.com/en/Products/DeepFreeze/DeepFreezeCorporate.aspx

If you're not familiar with it, the way it works is that you have a workstation installer that runs on client machines that talks to an admin console. The console can even run on your computer and you can quickly perform actions on multiple machines such as reboot, reboot frozen (no changes are saved), reboot thawed (the reverse). You can create events for all the machines as well e.g. restart at x time etc. It also has support for WSUS.

If you image the machines, you can have a second piece of software called a seed that you install on the image. Once the new machine is configured, it serves as a beacon and talks to the console. That enables you to launch the full workstation install without even needing to walk to the client computer. On the user end, it appears as if they can make changes, but once it restarts, everything is gone. alt text

share|improve this answer
    
Something like this may work, but we don't have the funding to purchase a license for it. Thanks for the info though –  Doltknuckle Oct 27 '10 at 20:49
    
If you like DeepFreeze, kiss any useful form of Windows administration goodbye. We had some customers insist on it on our images, and we refused. Good luck coordinating system restarts with "thaw sessions." Also, due to its popularity in the school systems in the US, many clever students put effort into castrating it. –  ajstein Oct 28 '10 at 5:06
    
I understand where you're coming from and it is not a solution for everyone. We have not had any issues with the students disabling it though. As a matter of fact knowing that all data is wiped clean every night, forces them to have copies of their data. Not sure what you mean by coordinating system restarts with thaw sessions. Do you mean being able to invoke things such as windows updates when the clients are in "thawed mode" ? –  Bourne Oct 28 '10 at 7:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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