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

Jerold Schulman

November 30, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today


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 documentsAutomatic caching of documentsAutomatic caching of programs and documentsCaching disabled.

OLCNS.BAT contains:

@echo offsetlocal ENABLEDELAYEDEXPANSIONset 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)endlocalgoto :EOF:parseif "%1" EQU "" goto :EOFset sn=%1set sp=set cc=call :parse1 %1if "%sp%" EQU "" goto :EOFif "%cc%" EQU "" goto :EOFif "%sp:~1,1%" NEQ ":" goto :EOF@echo "%sn%","%sp%","%cc%"goto :EOF:parse1for /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!)



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like