Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file to delete old cached user profiles (using builtin commands)

Status
Not open for further replies.

hgate73

IS-IT--Management
Feb 22, 2008
80
US
I've written a few batch files before, but this one I'm a little stuck on.

Some of our computers that we inherited haven't been imaged since 2007, but they are running fine (albiet slowly). I looked and they have 40, 50, sometimes up to 80 cached profiles (in "Documents and Settings") from old users that don't exist anymore.

Is there a quick and easy way (using the built-in windows commands, rmdir, del, etc) to remove all profiles older than n? Some of them are pretty big and it takes too long to do it manually.

Obviously I'd need to exclude the Administrator folder.

I was thinking something like

set EXCLUDED_PROFILE=Administrator
rmdir /s /q *

 
Smah,

That tool does almost exactly what I want. the problem is that it's deleting local accounts as well...I need those to stay there.

 
the /P switch prompts you (yes/no) for each profile that meets the /D days condition. Will that work?
 
grrr, no :-(

It needs to run fully automated in a batch file, otherwise I'd have to go sit at every PC and watch it work.
 
Okay, I solved it.

The /R switch says to delete only roaming profile caches - however, we are not using Roaming Profiles, so that didn't work.

HOWEVER, when it deletes profile caches older than xx days, even if it deletes a local account folder (i.e. "helpdesk" or something) the account itself is not deleted, only the Documents and Settings folder.

The user folder is recreated when you log back in.

Problem solved!
 
Just FYI, here's the script I ended up creating, feel free to plagiarize :)

It ran like a champ.

Substitute your own system names for ours.

Code:
:: Purpose:         Deletes old cached user profiles in Windows 2000/XP for all of our teams computers
:: Requirements:    1. Run this script with network admin rights
::                  2. delprof.exe from Microsoft must be in any of these locations:
::                      a) the directory you run this script from
::                      b) in the PATH variable
::                      c) c:\windows\system32\ 
:: Author:          Habur Gate (hgate73 at live dot com)
:: Version:         1.0
:: History:         1.0 Initial write
:: Notes:           Edit the list of system names below (where the script performs the delete) to reflect your own system names

:: Prep
@echo off
title Orbital Cached Profile Nuker
set VERSION=1.0
cls

:: User notice
color 0c
echo.
echo  *********************************************************
echo  *                                                       *
echo  *         ORBITAL CACHED PROFILE NUKER (OCPN)           *
echo  * ----------------------------------------------------- *
echo  * Nuke them from orbit. It's the only way to be sure.   *
echo  *                                                       *
echo  * RULES for a safe and happy nuking:                    *
echo  * 1. Run this script with NETWORK ADMIN rights. Local   *
echo  *    admin rights won't work.                           *
echo  * 2. Run this script from the desktop, NOT a network    *
echo  *    path.                                              *            
echo  * 3. "delprof.exe" must be in the same directory as     *
echo  *    this script. If you don't have it, Google and      *
echo  *    download it.                                       *
echo  *                                                       *
echo  *********************************************************
echo.
echo  The next screen will let you set the number of days.
echo.
pause
color 07
cls

:: Ask user how many days old the profiles should be before getting nuked
echo.
echo  *********************************************************
echo  *                                                       *
echo  *                 IT'S NUKING TIME                      *
echo  * ----------------------------------------------------- *
echo  * Windows 2000/XP caches user profiles when you login.  *
echo  * Over time these use up a lot of space. Annoying.      *
echo  *                                                       *
echo  * This script deletes those old profiles by using       *
echo  * "delprof.exe" from Microsoft.                         *
echo  *                                                       *
echo  * After you enter the number of days and hit "enter"    *
echo  * the script will begin nuking!                         *
echo  *                                                       *
echo  *********************************************************
echo.
set /p DAYS=Nuke profiles older than how many days? (21 recommended): 

:: HIROSHIMA!
title Nuking profiles, please wait...
cls
echo.
echo Nuking cached profiles older than %DAYS% days. Please wait for radiation to clear...
echo. 
delprof /Q /I /C:\\dt114601 /D:%DAYS%
delprof /Q /I /C:\\dt33202 /D:%DAYS%
delprof /Q /I /C:\\dt33210 /D:%DAYS%
delprof /Q /I /C:\\dt37711 /D:%DAYS%
delprof /Q /I /C:\\nb653001 /D:%DAYS%
delprof /Q /I /C:\\dt653001 /D:%DAYS%
delprof /Q /I /C:\\dt653002 /D:%DAYS%
delprof /Q /I /C:\\dt653003 /D:%DAYS%
delprof /Q /I /C:\\dt653004 /D:%DAYS%
delprof /Q /I /C:\\dt67806 /D:%DAYS%
delprof /Q /I /C:\\dt67808 /D:%DAYS%
echo.
echo Done nuking. Profiles older than %DAYS% were obliterated.
echo.
pause
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top