Skip navigation

Q. How can I generate a CSV file containing a server's shares and their share permissions?

Using SrvCheck,exe, I have scripted ShrPerms.bat to generate a CSV file containing:

"ComputerName","ShareName","UserOrGroup","ForCorRorU"

like:

"jsi001","Util","NT AUTHORITY\Authenticated Users","C"
"jsi001","Util","JSIINC\Domain Admins","F"
"jsi001","PCCW","Everyone","R"
"jsi001","PCCW","JSIINC\Domain Admins","F"
The syntax for using ShrPerms.bat is:

ShrPerms ComputerName CSVfile

Where:

ComputerName is the NetBIOS computer name of the 'server'.

CSVfile      is the fully qualified file name of the CSV to be generated.
ShrPerms.bat contains:
@echo Off
setlocal
if \{%2\}==\{\} goto err1
setlocal
set comp=%1
set comp=%comp:"=%
set cmp=%comp:\=%
set comp="\\%cmp%"
set cmp="%cmp%"
set csv=%2
if exist %csv% del /f /q %csv%
for /f "Tokens=*" %%a in ('srvcheck %comp%') do (
 set line=%%a
 call :parse
)
endlocal
goto :EOF
:parse
if "%line:~0,1%" EQU "\" goto :setshr
set wrk=%line:Full Control=%
if "%line%" NEQ "%wrk%" set perm="F"&goto out
set wrk=%line:Change=%
if "%line%" NEQ "%wrk%" set perm="C"&goto out
set wrk=%line:Read=%
if "%line%" NEQ "%wrk%" set perm="R"&goto out
set perm="U"
:out
set obj=%wrk:  =#%
for /f "Tokens=1 Delims=#" %%b in ('@echo %obj%') do (
 set obj="%%b"
)
set obj=%obj: "="%
@echo %cmp%,%shr%,%obj%,%perm%>>%csv%
goto :EOF
:setshr
for /f "Tokens=2 Delims=\" %%s in ('@echo %line%') do (
 set shr="%%s"
)
goto :EOF
:err1
@echo Syntax: ShrPerms ComputerName CSVfile
endlocal


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