Re: Batch file to delete old profiles, cant figure out where to set the parameters or how to output a log
- From: Jeffery Hicks <"jhicks[at]SAPIEN.com">
- Date: Fri, 16 Feb 2007 12:18:06 -0500
On 16 Feb 2007 08:52:21 -0800, im1crazymf wrote:
On Feb 16, 9:30 am, Jeffery Hicks <"jhicks[at]SAPIEN.com"> wrote:
On 16 Feb 2007 05:48:30 -0800, im1crazymf wrote:
Just need to know where to enter criteria.
I'm trying to use a batch file to delete old profiles.
I found this script onhttp://www.jsifaq.com/SF/Tips/Tip.aspx?id=6360
but I need to figure out how to set it to delete any user profiles
older than 90days unless I specify a name like smithj.
I would also like it to output a log to c:\ showing what was deleted.
I've tried modifying the following line
from DelProfile NNdays [KeepUserName]
to DelProfile 90days [Keep jsmith]
But it didn't work?
Thanks all!
Script below:
@echo off
setlocal
set keep=$$$$$$$$
if {%1}=={} goto syntax
set older=%1
if "%older%" EQU "0" goto OK
if "%older:~0,1%" LEQ "0" goto syntax
if "%older:~0,1%" GTR "9" goto syntax
:OK
if not {%2}=={} set keep=%2
set bypass=N
set pipkey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
\ProfileListregedit /a %TEMP%\profilelist.reg "HKEY_LOCAL_MACHINE
\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
set today=%date%
if "%today:~0,1%" GTR "9" set today=%date:~4%
set today=%today:/=%
set today=%today:~4,4%%today:~0,4%
set todayyy=%today:~0,4%
set todaymm=%today:~4,2%
set todaydd=%today:~6,2%
call jsidatem %todayyy% %todaymm% %todaydd% - %older%
for /f "Skip=5 Tokens=7 Delims=\]" %%a in ('type %TEMP%
\profilelist.reg') do set sid=%%a&call :getpip
endlocal
goto :EOF
:syntax
@echo Syntax: DelProfile NNdays [KeepUserName]
endlocal
goto :EOF
:IIIS
set bypass=N
If /i %1 EQU "%keep%" set bypass=Y&goto :EOF
set param=%1
set param=%param:"=%
If "%param:~0,5%" EQU "IUSR_" set bypass=Y&goto :EOF
If "%param:~0,5%" EQU "IWAM_" set bypass=Y&goto :EOF
goto :EOF
:getpip
for /f "Tokens=8 Delims=-" %%b in ('@echo %sid%') do set admin=%%b
if "%admin%"=="" goto :EOF
if "%admin%"=="500" goto :EOF
for /f "Skip=3 Tokens=2*" %%b in ('reg QUERY "%pipkey%%sid%" /v
ProfileImagePath') do call set pip=%%c
for /f "Tokens=2-5 Delims=\" %%b in ('@echo %pip%') do set usr1=%
%b&set usr2=%%c&set usr3=%%d&set usr4=%%e
if not "%usr4%"=="" call :IIIS "%usr4%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr3%"=="" call :IIIS "%usr3%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr2%"=="" call :IIIS "%usr2%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr1%"=="" call :IIIS "%usr1%"&if "%bypass%" EQU "Y"
goto :EOF
for /f "Tokens=1,4" %%b in ('dir "%pip%\ntuser.dat" /4 /a /tW ^|
Findstr /I /L "NTUSER.DAT"') do set dstring=%%b
set dstring=%dstring:/=%
set dstring=%dstring:~4,4%%dstring:~0,4%
if "%dstring%" GTR "%AYMD%" goto :EOF
@echo Delete "%pip%"
reg DELETE "%pipkey%%sid%" /f
RD "%pip%" /s /q
The username is optional which is why he shows it in brackets. Try this:
DelProfile 90 jsmith
I think that's the syntax you need.
--
Jeffery Hicks
SAPIEN Technologies - Scripting, Simplified.www.SAPIEN.com
VBScript & Windows PowerShell Training -www.ScriptingTraining.com/classes.asp
Windows PowerShell? -www.SAPIENPress.com/powershell.asp
blog:http://blog.SAPIEN.com
blog:http://jdhitsolutions.blogspot.com- Hide quoted text -
- Show quoted text -
Thanks I'll try it.
How about the log file any clues?
If you want to save the output from the batch file run it with redirection:
DelProfile 90 jsmith >>c:\delproflog.txt
Use >> to append to an existing file and > to overwrite it.
--
Jeffery Hicks
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com
VBScript & Windows PowerShell Training -
www.ScriptingTraining.com/classes.asp
Windows PowerShell? - www.SAPIENPress.com/powershell.asp
blog: http://blog.SAPIEN.com
blog: http://jdhitsolutions.blogspot.com
.
- Follow-Ups:
- References:
- Batch file to delete old profiles, cant figure out where to set the parameters or how to output a log
- From: im1crazymf
- Re: Batch file to delete old profiles, cant figure out where to set the parameters or how to output a log
- From: Jeffery Hicks
- Re: Batch file to delete old profiles, cant figure out where to set the parameters or how to output a log
- From: im1crazymf
- Batch file to delete old profiles, cant figure out where to set the parameters or how to output a log
- Prev by Date: Re: Batch file to delete old profiles, cant figure out where to set the parameters or how to output a log
- Next by Date: Re: Batch file to delete old profiles, cant figure out where to set the parameters or how to output a log
- Previous by thread: Re: Batch file to delete old profiles, cant figure out where to set the parameters or how to output a log
- Next by thread: Re: Batch file to delete old profiles, cant figure out where to set the parameters or how to output a log
- Index(es):
Relevant Pages
|
Loading