Skip navigation

JSI Tip 8767. How can I report a user's or Group's permissions on a server's shares?


I have scripted UserSharePerms.bat to report a user's or group's permissions on all the shares of one or more specified servers.

The syntax for using UserSharePerms.bat is:

UserSharePerms UserOrGroup ServerName1 \[ServerName2 ... ServerNameN\]

Where UserOrGroup is the user or group you wish to enumerate, and ServerNameX is a list of servers.

NOTE: UserSharePerms.bat uses RMTShare.exe, which must be located in a folder that is in your PATH.

Sample Usage

usershareperms Admin JSI001 JSI009

NOTE: All accounts and groups that have the string Admin in their name will be returned.

"\\JSI001\print$","BUILTIN\Administrators","FULL CONTROL"
. . .
"\\JSI001\NETLOGON","BUILTIN\Administrators","FULL CONTROL"
"\\JSI001\HP2250","BUILTIN\Administrators","FULL CONTROL"
. . .
"\\JSI009\ZIPNEW","JSIINC\Domain Admins","FULL CONTROL"
"\\JSI009\ZZZCDUMP","JSIINC\Administrator","FULL CONTROL"
UserSharePerms.bat contains:
@echo off
if \{%2\}

\{\} @echo Syntax: UserSharePerms UserOrGroup ServerName1 \[ServerName2 ... ServerNameN\]&goto :EOF setlocal set UserOrGroup=%1 set UserOrGroup=%UserOrGroup:"=% :loop if \{%2\}

\{\} goto finish set server=%2 shift set server=%server:\=% for /f "Skip=4 Tokens=*" %%s in ('rmtshare \\%server%') do ( if /i "%%s" NEQ "The command completed successfully." set line=%%s&call :parses ) goto loop :finish endlocal goto :EOF :parses set work=%line: =#% set /a cnt=0 set share= :ploop call set char=%%work:~%cnt%^,1%% if "%char%" EQU "#" goto getshare if "%char%" EQU ":" goto fixshare set share=%share%%char% set /a cnt=%cnt% + 1 if %cnt% LSS 65 goto ploop goto :EOF :fixshare set /a cnt=%cnt% - 2 call set share=%%share:~0,%cnt%%% :getshare set Perm=N for /f "Skip=3 Tokens=*" %%p in ('rmtshare \\%server%\"%share%"') do ( set line=%%p&call :parsep ) goto :EOF :parsep if /i "%line%" EQU "The command completed successfully." goto :EOF if "%Perm%" EQU "Y" goto parsep1 if /i "%line%" EQU "Permissions:" set Perm=Y goto :EOF :parsep1 for /f "Tokens=1* Delims=:" %%a in ('@echo %line%') do set who=%%a#&set what=#%%b set who=%who: #=% set who=%who:#=% set OK=N for /f "Tokens=*" %%u in ('@echo %who%^|FINDSTR /I /L /C:"%UserOrGroup%"') do ( set OK=Y ) if /i "%OK%" NEQ "Y" goto :EOF set what=%what:# =% set what=%what:#=% @echo "\\%server%\%share%","%who%","%what%"



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