Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Need a script to disable caching on thousands of shares

Posted on 2011-10-26
5
Medium Priority
?
277 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:ITProOnTheGo
  • 3
5 Comments
 
LVL 8

Expert Comment

by:Amit Khilnaney
ID: 37035853
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
 
LVL 10

Expert Comment

by:ReneGe
ID: 37035985
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
 
LVL 42

Expert Comment

by:kevinhsieh
ID: 37036169
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
 
LVL 10

Accepted Solution

by:
ReneGe earned 2000 total points
ID: 37037430
@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
 
LVL 10

Expert Comment

by:ReneGe
ID: 37039455
Glad I could help.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question