JSI Tip 8855. What files are owned by a security principal?

In tip 8308 ยป How can I report file system objects by owner, we reported the ownership of all file system objects.

I have scripted OwnsWhat.bat to report the files that are owned by a specified security principle.

The syntax for using OwnsWhat.bat is:

OwnsWhat SecPr ReportFile Path1 \[Path2 ... PathN\]


SecPr        is the security principal, like JSIINC\Jerry or JSI009\Jerry, or Builtin\Administrators, etc..
ReportFile   is the fully qualified file name of the file that will contain the list of files owned by SecPr.
PathX        is the location(s) to search, like C:\ or "C:\Documents and Settings" or \\ServerName\ShareName.
OwnsWhat.bat contains:
@echo off
if \{%3\}

\{\} @echo Syntax: OwnsWhat SecPr ReportFile Path1 \[Path2 ... PathN\]&goto :EOF setlocal set owner=%1 set owner=%owner:"=% set report=%2 if exist %report% del /q %report% set fo=Findstr /L /I /C:"%owner%" :loop if \{%3\}

\{\} goto finish for /f "Tokens=*" %%f in ('dir %3 /b /s /a-d') do ( for /f "Tokens=*" %%o in ('dir /q "%%f"^|%fo%') do ( @echo "%%f">>%report% ) ) shift goto :loop :finish endlocal

Hide 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.