Deleting accounts and folders

  • Thread starter Thread starter sherman
  • Start date Start date
S

sherman

is there a setup to where I can delete the account off of
active directory as well as deleting the account's folder
at the same time?
 
is there a setup to where I can delete the account off of
active directory as well as deleting the account's folder
at the same time?


You could use the following batch:

@echo off
if {%1}=={} @echo Syntax: DelUser UserName&goto :EOF
setlocal
set user=%1
for /f "Tokens=2*" %%a in ('net user %user% /domain^|Findstr /i /L /C:"User
name" /C:"User profile" /C:"Home directory"') do (
REM The above 2 lines are 1 line
set type=%%a
set data=%%b
call :del
)
if /i "%user%" NEQ "%usr%" goto notfound
net user %user% /delete /domain
if exist "%home%" rd /s /q "%home%"
if exist "%profile%" rd /s /q "%profile%"
endlocal
goto :EOF
:notfound
@echo User %user% not found.
endlocal
goto :EOF
:del
if /i "%type%" EQU "name" set usr=%data%&goto :EOF
if /i "%type%" EQU "profile" set profile=%data%&goto :EOF
set home=%data%


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top