Need a script to disable caching on thousands of shares

How do I write a script that will run "net share sharename /cache:none" against thousands of sharenames? I have a list of the sharenames in a file, I just don't want to run these manually and I am not a scripter.
ITProOnTheGoAsked:
Who is Participating?
 
ReneGeCommented:
@ITProOnTheGo:
I forgot to tell you what file format my batch file will work with.

FILE NAME: datafile.txt
computername1,sharename1
computername1,sharename2
computername1,sharename3
computername2,sharename1
computername2,sharename2

If you want to use a more common CSV File, use the following format, "computername1","sharename1", change the extension to csv and use the following modified batch file.

Note that I also added "%~dp0". This will add the path where the batch file is to the CSV file. In other words, this will force the path of the csv file to be in the same folder as the batch file.
@ECHO OFF

REM assuming your data file format is; computer,sharename
FOR /F "usebackq tokens=1,2 delims=," %%A in ("%~dp0datafile.csv") DO (
	ECHO For Computer [%%~A] at sharename [%%~B]
	psexec %%~A net share %%~B /cache:none
)
PAUSE
EXIT

Open in new window

0
 
Amit KhilnaneyCommented:
I guess this question is somewhat related to this..
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Q_22544648.html

Open in new window

0
 
ReneGeCommented:
Well it is not asy to write a batch file that will do what you need, without you sharing a sample the your file. Does not have to be the exact data.

Anyway, here is a very simplistic batch file that will do what you need, but, will most likely not work as is because, i have no clue what you data file is made of.

@ECHO OFF

REM assuming your data file format is; computer,sharename
FOR /F "usebackq tokens=1,2 delims=," %%A in ("datafile.txt") DO (
	ECHO For Computer [%%A] at sharename [%%B]
	psexec %%A net share %%B /cache:none
)
PAUSE
EXIT

Open in new window

0
 
kevinhsiehCommented:
Why don't you take your list, and edit the beginning and end of the lines so that they match the command you are trying to run? I like to use Excel to get it all into easily columns for easy editing. Then you can just save the file as a text file with .cmd extension. Then just run the file.
0
 
ReneGeCommented:
Glad I could help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.