Using WhoOwns.bat from How can I get the DIR command to return a file's owner in a batch script, I have scripted SFOwner.bat to report the file system objects owned by a specified security principal on a remote share.

The syntax for using SFOwner.bat is:

SFOwner Share Owner

Where:

<b>Share</b>    is the share URL that you want to enumerate, like \\ServerName\ShareName.

<b>Owner</b>    is a mask that matches the owner, like:
         <b>JSIINC\Jerry</b> -  to match <b>Jerry</b> from <b>JSIINC.COM</b> exactly.
         <b>\Jerry</b>       -  to match both local and domain <b>Jerry</b>.
         <b>Admin</b>        -  to match <b>Domain Admins</b>, <b>Administrator</b>, and the <b>Administrators</b> group.
         <b>C\Je</b>         -  to match <b>Jerry</b> and <b>Jennifer</b> from <b>JSIINC.COM</b>.
The output is displayed on the console, but can be redirected to a file. Each line of output contains:

"\\ServerName\ShareName\File System Object","Matching Sercurity Principal"

Like:

"\\JSI009\Zipnew","JSIINC\Jerry"
"\\JSI009\Zipnew\FAX","JSIINC\Jerry"
"\\JSI009\Zipnew\Saved\HappyHal.jpg","JSIINC\Jerry"
"\\JSI009\Zipnew\Saved\Harrods.pdf","JSIINC\Jennifer"
"\\JSI009\Zipnew\Saved\Voting_Machine.wmv","JSIINC\Jerry"
SFOwner.bat contains:
@echo off
if \{%2\}==\{\} @echo Syntax: call SFOwner Share Owner&goto :EOF
setlocal ENABLEDELAYEDEXPANSION
set object=%1
set object="%object:"=%"
set owner=%2
set owner=%owner:"=%
call WhoOwns %object% who
call set work=%%who:%Owner%=%%
if "%work%" NEQ "%who%" @echo %object%,"%who%"
for /f "Tokens=*" %%a in ('dir %object% /b /s /a') do (
 call WhoOwns "%%a" who
 call set work=!!who:%Owner%=!!
 if "!work!" NEQ "!who!" @echo "%%a","!who!"
)
endlocal