Skip navigation

JSI Tip 8308. How can I report file system objects by owner?


I have scripted OwnerReport.bat to sort / report file system objects by owner.

The syntax for using OwnerReport.bat is:

OwnerReport DriveOrFolder ReportFile

Where DriveOrFolder is the drive or folder you wish to enumerate, and ReportFile is the file that will contain the report. A small sample of the report file might look like:


04/16/2001  17:39            17,172 JSI009\Administrator   C:\WINDOWS\SYSTEM32\SPOOL\DRIVERS\W32X86\3\ADIST5.PPD
01/18/2001  12:03            26,056 JSI009\Administrator   C:\WINDOWS\SYSTEM32\SPOOL\DRIVERS\W32X86\3\pscript.hlp
02/09/2001  16:01           792,644 JSI009\Administrator   C:\WINDOWS\SYSTEM32\SPOOL\DRIVERS\W32X86\3\PSCRIPT.NTF
05/03/2003  15:37             6,976 JSI009\Jerry           C:\Documents and Settings\All Users\Application Data\Microsoft\User Account Pictures\Jerry.bmp
06/04/2004  15:15             1,661 JSI009\Jerry           C:\Documents and Settings\All Users\Start Menu\Programs\Administrative Tools\Internet Information Services.lnk
05/03/2003  16:18             1,109 JSI009\Jerry           C:\Documents and Settings\All Users\Start Menu\Programs\Administrative Tools\Server Extensions Administrator.lnk
05/03/2003  19:15    \{DIR\}          JSI009\Jerry           C:\Documents and Settings\All Users\Start Menu\Programs\Dell Accessories
05/03/2003  19:15               281 JSI009\Jerry           C:\Documents and Settings\All Users\Start Menu\Programs\Dell Accessories\Dell ResourceCD.lnk
07/28/2004  14:40             1,024 JSI009\Jerry           C:\Documents and Settings\Jerry\ntuser.dat.LOG
NOTE: OwnerReport.bat uses ShellESC.exe, which must be located in a folder that is in your path.

OwnerReport.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: OwnerReport DriveOrFolder ReportFile&goto:EOF
if not exist %1 @echo Syntax: OwnerReport DriveOrFolder ReportFile - %1 NOT found.&goto:EOF
setlocal
set top=%1
set RF=%2
if exist %RF% del /q %RF%
if exist "%TEMP%\Owner.tmp" del /q "%TEMP%\Owner.tmp"
if exist "%TEMP%\OwnerTree1.tmp" del /q "%TEMP%\OwnerTree1.tmp"
set object=%top%
set object=%object:"=%
for /f "Tokens=*" %%a in ('dir %top% /ad /q^|findstr /L /V /c:"&"^|findstr /i /L /c:"<DIR>"^|findstr /c:" ."^|shellesc') do (
  set line=%%a
  call :folder
)
for /f "Tokens=*" %%f in ('dir %top% /s /ad /b') do (
 @echo %%f>>"%TEMP%\OwnerTree1.tmp"
)
sort "%TEMP%\OwnerTree1.tmp" /O "%TEMP%\OwnerTree2.tmp"
del /q "%TEMP%\OwnerTree1.tmp"
for /f "Tokens=*" %%f in ('type "%TEMP%\OwnerTree2.tmp"') do (
 set object=%%f
 call :tree >nul 2>&1
)
sort /+37 "%TEMP%\Owner.tmp" /O %RF%
del /q "%TEMP%\Owner.tmp"
del /q "%TEMP%\OwnerTree2.tmp"
endlocal
goto :EOF
:folder
set line=%line:^=\{DIR\}%
set line=%line:~0,59%
@echo %line%%object%>>"%TEMP%\Owner.tmp"
goto :EOF
:file
set work=%line:~59%
set line=%line:~0,59%
@echo %line%%object%\%work%>>"%TEMP%\Owner.tmp"
goto :EOF
:tree
for /f "Tokens=*" %%a in ('dir "%object%" /q /ad^|findstr /L /V /c:"&"^|findstr /i /L /c:"<DIR>"^|findstr /c:" ."^|shellesc') do (
 set line=%%a
 call :folder
)
for /f "Tokens=*" %%b in ('dir "%object%" /q /a-d /a^|findstr /L /V /c:"&"^|findstr /L /c:"/"^|findstr /i /L /V /c:"<DIR>" /c:" ."^|shellesc') do (
 set line=%%b
 call :file
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish