Re: Finding Orphaned Home Directories

From: Jerold Schulman (Jerry_at_jsiinc.com)
Date: 09/30/04


Date: Thu, 30 Sep 2004 08:52:16 -0400

On Wed, 29 Sep 2004 12:49:06 -0700, "Jake" <anonymous@discussions.microsoft.com>
wrote:

>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



Relevant Pages

  • Re: Obtaining Last Logon Time for Domain User
    ... Subject: Re: Last time each NT account was accessed ... > framework 1.1 to run this tool (you can get it from Windows Update). ... >> goto:EOF ...
    (microsoft.public.windows.server.active_directory)
  • Re: Deleting Empty File Folders
    ... if ==@echo Syntax DelMT Folder&goto:EOF ... if "%delSW%" EQU "Y" goto:loop ... Windows: General MVP ...
    (microsoft.public.win2000.file_system)
  • Re: Finding whether PC is Windows 2000 or Windows XP
    ... > in is a Windows XP or Windows 2000? ... goto:EOF ... echo/This computer is running Win2000. ...
    (microsoft.public.win2000.applications)
  • RE: After migrating Folders/Files from NT4 SBS 4.5 All are READ ONLY.
    ... The Default Permissions for Home Folders in Windows 2000 and Windows 2003 ... programs running on the server, or there are problems negotiating SMB ... This posting is provided "AS IS" with no warranties, ...
    (microsoft.public.windows.server.sbs)
  • Re: home directories
    ... the domain fifty percent are windows 2000 pro the other half are XP ... other users home folders. ... account and the admin account to full control on the share permissions, ... Download details Windows Server 2003 Access-based Enumeration: ...
    (microsoft.public.windows.server.networking)

Loading