JSI Tip 9936. How can I output, in CSV format, the offline cache settings for my shares using the net share command?


I have scripted OLCNS.BAT to output, in CSV format, the offline cache settings for my shares, by parsing the output of the net share command.

The syntax for using OLCNS.BAT is:

OLCNS

Output is displayed on the console in the following format:

"Share Name","File System Path","Cache Setting"

Where Cache Setting can be one of the following:

Manual caching of documents
Automatic caching of documents
Automatic caching of programs and documents
Caching disabled.
OLCNS.BAT contains:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set f1=Findstr /l /n /v /c:"*$"
set f2=Find /V "The command completed successfully."
for /f "Skip=4 Tokens=1* Delims=:" %%a in ('net share ^|%f1%^|%f2%') do (
 set line=%%b
 if "!line:~0,1!" NEQ " " call :parse %%b
)
endlocal
goto :EOF
:parse
if "%1" EQU "" goto :EOF
set sn=%1
set sp=
set cc=
call :parse1 %1
if "%sp%" EQU "" goto :EOF
if "%cc%" EQU "" goto :EOF
if "%sp:~1,1%" NEQ ":" goto :EOF
@echo "%sn%","%sp%","%cc%"
goto :EOF
:parse1
for /f "Tokens=*" %%x in ('net share %1') do (
 set line=%%x
 if "!line:~0,18!" EQU "Path              " set sp=!line:~18!
 if "!line:~0,18!" EQU "Caching           " set cc=!line:~18!
)



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