Guest User

OCPN: Orbital Cached Profile Nuker v1

a guest
Jun 25th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. :: Purpose:         Deletes old cached user profiles on computers listed in the names file
  2. :: Requirements:    1. Run this script with a network admin account
  3. ::                  2. delprof.exe is required and may be in any of these locations:
  4. ::                      a) the directory you run this script from
  5. ::                      b) in the PATH variable
  6. ::                      c) c:\windows\system32\
  7. ::                  3. Put the names of your computers, one per line, in the names file in the same directory as this script
  8. :: Author:          vocatus on reddit.com/r/sysadmin
  9. :: History:         1.5c Commenting cleanup
  10. ::                  1.5b Fixed hardcoded log entry line
  11. ::                  1.5  Switched reading from names file to using the system name
  12. ::                       Added logging function
  13. ::                  1.4  Updated menus and comments
  14. ::                  1.3  Updated to allow for passing the number of days as an argument
  15. ::                  1.2  Changed script to use a FOR loop to read a list of pc names from a file instead of hard-coding them
  16. ::                  1.1  Changed around menus, the first screen is now informational, the second is the "action" screen
  17. ::                  1.0  Initial write
  18.  
  19. :: Prep
  20. @echo off
  21. cls
  22. set VERSION=1.5b
  23. title Orbital Cached Profile Nuker v%VERSION%
  24.  
  25.  
  26. :::::::::::::::
  27. :: VARIABLES :: -- set these
  28. :::::::::::::::
  29. :: Set log info here, no trailing slash (\) on directory names
  30. set LOGPATH=%SystemDrive%\Logs
  31. set LOGFILE=%COMPUTERNAME%_OCPN.log
  32.  
  33. :: Specify the name of the text file containing the list of systems you want to run against.
  34. :: This file must exist!
  35. set NAMES_FILE=names.txt
  36.  
  37. :: Connection timeout in seconds
  38. set TIMEOUT=7
  39.  
  40. :: Don't edit this variable
  41. set DAYS=%1
  42.  
  43. :: Test for run-once
  44. if '%1'=='' set DAYS=60&& goto manual
  45.             set DAYS=%1&& goto auto
  46. cls
  47.  
  48. :: User notice
  49. :manual
  50. color 0c
  51. echo.
  52. echo  *********************************************************
  53. echo  *                                                  v%VERSION% *
  54. echo  *         ORBITAL CACHED PROFILE NUKER (OCPN)           *
  55. echo  * ----------------------------------------------------- *
  56. echo  * Nuke them from orbit. It's the only way to be sure.   *
  57. echo  *                                                       *
  58. echo  * Windows 2000/XP caches user profiles when you login.  *
  59. echo  * Over time these use up a lot of space. Annoying.      *
  60. echo  *                                                       *
  61. echo  * This script deletes those old profiles by using       *
  62. echo  * "delprof.exe" from Microsoft.                         *
  63. echo  *                                                       *
  64. echo  *********************************************************
  65. echo.
  66. echo  The next screen will let you set the number of days.
  67. echo.
  68. pause
  69. color 07
  70. cls
  71.  
  72. :: Ask user how many days old the profiles should be before getting nuked
  73. echo.
  74. echo  *********************************************************
  75. echo  *                                                       *
  76. echo  *                  IT'S NUKING TIME                     *
  77. echo  * ----------------------------------------------------- *
  78. echo  *                                                       *
  79. echo  * RULES for a safe and happy nuking:                    *
  80. echo  *                                                       *
  81. echo  * 1. Run this script with NETWORK ADMIN rights. Local   *
  82. echo  *    admin rights won't work.                           *
  83. echo  * 2. Run this script from the desktop, NOT a network    *
  84. echo  *    path.                                              *
  85. echo  * 3. "delprof.exe" must be in the same directory as     *
  86. echo  *    this script. If you don't have it, Google and      *
  87. echo  *    download it. (system32 is also okay)               *
  88. echo  *                                                       *
  89. echo  * After you enter the number of days and hit "enter"    *
  90. echo  * the script will begin nuking!                         *
  91. echo  *                                                       *
  92. echo  *********************************************************
  93. echo.
  94. set /p DAYS=Nuke profiles older than how many days? [%DAYS% recommended]:
  95.  
  96. :: HIROSHIMA!
  97. :auto
  98. title Nuking profiles, please wait...
  99. cls
  100. echo.
  101. echo Nuking cached profiles older than %DAYS% days. Please wait for radiation to clear...
  102. echo.
  103.  
  104. echo. > %LOGPATH%\%LOGFILE%
  105.  
  106. FOR /F %%i in (%NAMES_FILE%) do (
  107.     delprof /Q /I /C:\\%%i /D:%DAYS% >> %LOGPATH%\%LOGFILE%
  108.     )
  109. del %NAMES_FILE%
  110.  
  111. echo.
  112. echo Done nuking. Profiles older than %DAYS% days were obliterated.
  113. echo.
  114. pause
  115. title %USERNAME%
Add Comment
Please, Sign In to add comment