Question : Delprof via gpo on client bootup

Hi guys

quick question, is there anyway i can get delprof to start up on client computers on boot up via gpo? i would like an experts advice and how to do this correctly if it can be done!

i just want to be able to do this a few times every week, enable it in gpo for the day and turn it off. for the week. saves me the big job of running round the school like a headless chicken delprofing all machines!

many thanks

Phil

Answer : Delprof via gpo on client bootup

If you want to delete profiles older than a certain age I have a batch file for that which uses only Standard NT Commands.

 You could run the batch file I attached at start-up via GPO (  Or For for a user who is a local admin you can also do it using the Startup GPO or regular startup script method.)  See attached Code.

If you want to run the delpro utility instead, you will need to write a small batch file and execute that as a startup script via GPO (again Logon GPO or regular logon start-up script will require the user being a local Admin)

I'm not familiar with delpro syntax but I'm sure you are, so we will leave that up to you for now.

Things to know about running User Deletion Via GPO or otherwise:

Just note that start-up scripts execute as local system where as LOGON Scripts execute as the user who is logging on, so therefore you would need to run this as a Start-up script.

I'm not sure what you are looking to accomplish exactly with the delpro command, to delete all profile or profiles older than N Days.

If you only want to delete profiles older than N Days then you would not have to constantly enable and disable the GPO as you talked about doing.

OR if you still want to delete all profiles regardless of age, you could just include a test to see what day of the week it is, and run the command only if the day matches, again this way you would not have to manually enable and disable the GPO.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
::------------------------------------------------------------------------------------------------::
:: Script: DelOldUsers.Bat                                              					 	  ::
:: Version: 1.3                                                                                   ::
:: Copyright: Ben Personick                                                                       ::
:: Date: 2010-07-14                                                                               ::
::                                                                                                ::
::                                                                                                ::
:: Desc: Deletes User Directories Older than N Days												  ::
::                                                                                                ::
::------------------------------------------------------------------------------------------------::
:Begin
Echo Off


:Start-Prep
	SET ScriptName=DelOldUsers.Bat
	CALL :Start-Set-Date
	ECHO %TDate% - %TTime% -- Beginging Preparation for Script: %ScriptName%
	SET OldSysDrv=C:
	::FOR XP SET OldSysUsrDir=Documents and Settings 
	SET OldSysUsrDir=Users
	SET OldSysBase=%OldSysDrv%\%OldSysUsrDir%
	SET MaxAgeNTUser=60
	:: Set the Upgrade Day Variable
	SET UDay=%date:~7,2%
	:: Set the Upgrade Month Variable
	SET UMonth=%date:~4,2%
	:: Set the Upgrade Year variable
	SET UYear=%date:~10,4%
	CALL :Start-Number-Date %UDay% %UMonth% %UYear%
	SET CurrentDTotal=%DTotal%
	CALL :Start-Set-Date
	ECHO %TDate% - %TTime% (In days: %CurrentDTotal%) -- Preperation Complete - Script: %ScriptName% Begining
	
:End-Prep


:Start-Main

	CALL :Start-Set-Date
	ECHO %TDate% - %TTime% -- Begining to loop through User Directories in %OldSysBase%
	For /F "Tokens=*" %%B IN ('dir /A:D /B "%OldSysBase%\*"') DO CALL :Start-UserDir-Loop "%%B"
	GOTO End-UserDir-Loop 
	:Start-UserDir-Loop 
		::Skip needed system folders from being evaluated in Win XP
		IF /I %1=="All Users" GOTO :EOF
		IF /I %1=="Default User" GOTO :EOF
		::Skip needed system folders from being evaluated in Win Vista+
		IF /I %1=="Public" GOTO :EOF
		IF /I %1=="Default" GOTO :EOF
		::Set TUser variable to = Username without Quotes
		SET TUser=%~1
		CALL :Start-Set-Date
		ECHO %TDate% - %TTime% --  Looking for NTUser.dat older than %MaxAgeNTUser% Days In "%OldSysBase%\%TUser%"
		For /F "tokens=1-3" %%U IN ('dir "%OldSysBase%\%TUser%\NTUSER.dat" /A:H ^| Find /I "NTUser.dat"')  DO CALL :Start-NTUser-Loop "%%U"
		GOTO End-NTUser-Loop
		:Start-NTUser-Loop
			SET NDate=%~1
			CALL :Start-Set-Date
			IF /I "%TUser%"=="%NDate%" ECHO %TDate% - %TTime% -- CANNOT Locate NTUser.Dat!  Skipping "%OldSysBase%\%TUser%"!
			IF /I "%TUser%"=="%NDate%" GOTO :EOF
			:: Set the Upgrade Day Variable
			SET NDay=%NDate:~3,2%
			:: Set the Upgrade Month Variable
			SET NMonth=%NDate:~0,2%
			:: Set the Upgrade Year variable
			SET NYear=%NDate:~6,4%
			CALL :Start-Number-Date %NDay% %NMonth% %NYear%
			SET NTUserDate=%DTotal%
			:: HERE WE WILL CALL A COMPARE FUNCTION!
			CALL :Start-Compare-Date %CurrentDTotal% %NTUserDate%
			SET IsAge=%TDifference%
			IF %IsAge% GEQ %MaxAgeNTUser% CALL :Start-Delete-Directory "%OldSysBase%\%TUser%"
			REM ECHO %TDate% - %TTime% -- HERE WE WILL CALL A COMPARE FUNCTION! for %NDay% and %NMonth% and %NYear%
			
			GOTO :EOF
		:End-NTUser-Loop
		
		GOTO :EOF
	:End-UserDir-Loop 

	GOTO End
:End-Main

GOTO End-Subs
GOTO End
:Start-Subs
	GOTO End-Set-Date
	:Start-Set-Date
		SET TDate=%date:~10,4%-%date:~4,2%-%date:~7,2%
		SET TTime=%Time:~0,2%.%Time:~3,2%.%Time:~6,2%
		GOTO :EOF
	:End-Set-Date
	GOTO End-Number-Date
	:Start-Number-Date
		SET DDay=%1
		IF %DDay:~0,1%==0 SET DDAY=%DDay:~1,1%
		REM ECHO DDay = %DDay%
		IF %2 NEQ 02 GOTO End-Leap-Day
		:Start-Leap-Day
			IF %1 GTR 28 SET DDay=28
		:End-Leap-Day
		REM ECHO DDay = %DDay%
		SET DMonth=0
		REM ECHO DMonth = %DMonth%
		IF %2 GTR 01 SET DMonth=31
		REM ECHO DMonth = %DMonth%
		IF %2 GTR 02 SET /A DMonth=%DMonth%+28
		REM ECHO DMonth = %DMonth%
		IF %2 GTR 03 SET /A DMonth=%DMonth%+31
		REM ECHO DMonth = %DMonth%
		IF %2 GTR 04 SET /A DMonth=%DMonth%+30
		REM ECHO DMonth = %DMonth%
		IF %2 GTR 05 SET /A DMonth=%DMonth%+31
		REM ECHO DMonth = %DMonth%
		IF %2 GTR 06 SET /A DMonth=%DMonth%+30
		REM ECHO DMonth = %DMonth%
		IF %2 GEQ 07 SET /A DMonth=%DMonth%+31
		REM ECHO DMonth = %DMonth%
		IF %2 GEQ 08 SET /A DMonth=%DMonth%+31
		REM ECHO DMonth = %DMonth%
		IF %2 GEQ 09 SET /A DMonth=%DMonth%+30
		REM ECHO DMonth = %DMonth%
		IF %2 GEQ 10 SET /A DMonth=%DMonth%+31
		REM ECHO DMonth = %DMonth%
		IF %2 GEQ 11 SET /A DMonth=%DMonth%+30
		REM ECHO DMonth = %DMonth%
		SET /A DYear=%3*365
		REM ECHO DYear = %DYear%
		REM ECHO DTotal = %DDay% + %Dmonth% + %DYear%
		REM ECHO %DTotal%
		SET /A DTotal=%DDay%+%Dmonth%+%DYear%
		REM ECHO DTotal = %DTotal%
		GOTO :EOF
	:End-Number-Date
	GOTO End-Compare-Date
	:Start-Compare-Date
		SET Date1=%1
		SET Date2=%2
		ECHO Date1 = %Date1% Date2 = %Date2%
		SET /A TDifference=%Date1%-%Date2%
		ECHO Age Difference in days = %TDifference%
		GOTO :EOF
	:End-Compare-Date
	GOTO End-Delete-Directory
	:Start-Delete-Directory
		ECHO Now Running RMDir /S /Q %1
		RMDir /S /Q %1
		GOTO :EOF
	:End-Delete-Directory
	
	GOTO End
:End-Subs


:End
	CALL :Start-Set-Date
	ECHO %TDate% - %TTime% -- Script %ScriptName% Exiting!
	GOTO :EOF
Random Solutions  
 
programming4us programming4us