Finding Orphaned Home Directories

  • Thread starter Thread starter Jake
  • Start date Start date
J

Jake

Is there an automated way to compare Active\Disabled user
accounts with their corresponding home folders? I want to
know which home folders have been orphaned.
 
Jake said:
Is there an automated way to compare Active\Disabled user
accounts with their corresponding home folders? I want to
know which home folders have been orphaned.
No, ther is not built-in mechanism for that. But you can do it easily
with the script - check the Disabled and ExpirationDate status and then
list this inactive users home folders

If it is a problem for You to write such script e-mail me or post a
message here.
 
Is there an automated way to compare Active\Disabled user
accounts with their corresponding home folders? I want to
know which home folders have been orphaned.

If you have a Windows XP domain member (or Windows Server 2003), the following
will tell you which accounts have home folders that don't exist:

@echo off
setlocal
set qry1=dsquery * domainroot -filter
set qry2= "(&(objectCategory=Person)(objectClass=User))"
set qry3= -attr distinguishedName homeDirectory -L -limit 0
set qry=%qry1%%qry2%%qry3%
for /f "Tokens=1* Delims=:" %%a in ('%qry%') do (
set attr=%%a
set data=%%b
call :test
)
endlocal
goto :EOF
:test
set data=%data:~1%
if /i "%attr%" EQU "distinguishedName" set dn=%data%&goto :EOF
if "%data%" EQU "" goto :EOF
if exist %data% goto :EOF
@echo %dn% %data%

If you have home folders like \\Servername\Sharename\Username
(C:\users\Username) you can report user folders that don't have users:

@echo off
setlocal
for /f "Tokens=*" %%a in ('dir c:\users /b /ad') do (
set user=%%a
call :get
)
endlocal
goto :EOF
:get
set OK=N
call :quiet>nul 2>&1
if "%OK%" EQU "Y" goto :EOF
@echo %user%
goto :EOF
:quiet
for /f "Tokens=*" %%b in ('net user %user% /domain^|Find "Full Name"') do (
set OK=Y
)


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