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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script: Mass Windows old cached profile cleanup

Performance

Script: Mass Windows old cached profile cleanup

by  hgate73  Posted    (Edited  )
If you are in a highly transient environment like I am, you have hundreds of users logging into workstations they'll probably never use again. This script uses delprof.exe from Microsoft to crawl through the network and delete old cached profiles from the computers, potentially freeing up GIGS of space. You can set the number of days to anything you want. The script reads computer names from the "names.txt" file, one per line.

Put in a bat file.

Code:
:: Author:          hgate73 at gmail or yahoo
:: Purpose:         Deletes old cached user profiles
:: Requirements:    1. Run this script with network admin privileges
::                  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\
::                  3. Put the names of your computers, one per line, in a file called "names.txt" in the same directory as this script
:: Version:         1.3 Updated to allow for passing the number of days as an argument
::                  1.2 Changed script to use a FOR loop to read a list of pc names from a file instead of hard-coding them
:: History:         1.1 Changed around menus, the first screen is now informational, the second is the "action" screen
::                  1.0 Initial write

:: Prep
@echo off
cls
title Orbital Cached Profile Nuker
set VERSION=1.3
set NAMES_FILE=names.txt
set TIMEOUT=7
set DAYS=%1
if '%DAYS%'=='' goto manual
        goto auto
cls

:: User notice
:manual
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  * 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  *********************************************************
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  *                                                       *
echo  * RULES for a safe and happy nuking:                    *
echo  *                                                       *
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. (system32 is also okay)               *
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!
:auto
title Nuking profiles, please wait...
cls
echo.
echo Nuking cached profiles older than %DAYS% days. Please wait for radiation to clear...
echo.

FOR /F %%i in (%NAMES_FILE%) do delprof /Q /I /C:\\%%i /D:%DAYS%

echo.
echo Done nuking. Profiles older than %DAYS% days were obliterated.
echo.
pause
title %USERNAME%
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top