We’d like to remind Forumites to please avoid political debate on the Forum.
This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
Any Command Prompt / Batch Gurus?

mr_fishbulb
Posts: 5,224 Forumite

in Techie Stuff
I'm trying to automate the enumeration of shares on a network.
I've got a list of all host names, and using a batch file, I have created a txt file for each host containing the NET VIEW output.
Each file has something similar to:
Is there a way via the command prompt to strip the files of all but the share names (in blue)?
I was thinking of using FOR "tokens=1 delims= " in a batch file, but then I thought some of the shares contain a space in them.
Does anyone know if I can change delims= to have 2 spaces after it?
Or is there better way?
Cheers
I've got a list of all host names, and using a batch file, I have created a txt file for each host containing the NET VIEW output.
Each file has something similar to:
Share name Type Used as Comment ------------------------------------------------------------------------------- [COLOR=Navy]ShareName1[/COLOR] Disk [COLOR=Navy]ShareName2[/COLOR] Disk [COLOR=Navy]Share Name 3[/COLOR] Disk [COLOR=Navy]Very Long Share Name[/COLOR] Disk The command completed successfully.
Is there a way via the command prompt to strip the files of all but the share names (in blue)?
I was thinking of using FOR "tokens=1 delims= " in a batch file, but then I thought some of the shares contain a space in them.
Does anyone know if I can change delims= to have 2 spaces after it?
Or is there better way?
Cheers
0
Comments
-
No need if you have access to Excel.
You can just read the text files into a separate worksheet for each one and then do the necessaries in there, either with VBA or some fairly simple formulae.
If they are in a standard format, then you can use tab delimited format when reading them on to get them into separate cells and then do whatever else you need to do afterwards.:wall: Flagellation, necrophilia and bestiality - Am I flogging a dead horse? :wall:
Any posts are my opinion and only that. Please read at your own risk.0 -
Quite straightforward, provided that your environment always generates the output you post (mine certainly doesn't!). Create a BATch file containing
@echo off
setlocal
for /f "tokens=*" %%a in (' net view ^| find "Disk" ') do call :process "%%a"
:: I had to test this using the following line,
:: because I don't get the results you do from NET VIEW
::for /f "tokens=*" %%a in (' type mse.txt ^| find "Disk" ') do call :process "%%a"
endlocal
goto :eof
::
:process
:: whole string gets passed to this subroutine
set line=%1
:: remove the double-quotes
set line=%line:"=%
:: strip off the last five characters (the "Disk" text)
set line=%line:~0,-5%
:: dunno what you want to DO with the sharename here, so I've just echoed it
ECHO %LINE%
goto :eof
For each silly face replace it by : p (but without the space between the : and the p, of course!).
See how it goes!0 -
I've just reread your post, and it seems my test method was closer to your reality.
Post the names of the TXT files containing the share names you want to process (for example, is it *.txt in a directory?), and what output you want (names in a single file with the name of the host (presumably coming from Host1.txt, Host2.txt, and so on?), or one file per host name, or what)?
With any programming task you have to be very precise about the inputs and the outputs...!
BTW, if you have administrator access to all the hosts, you can access each one in a single BATch file to obtain a NET VIEW using Mark Russinovich's PSEXEC program. But you probably know that already!0 -
-
I tried the former, but there seems to be a line-length limit for Code! I will look for the latter,...0
-
-
Sorry for not replying yesterday - got completely engrossed in this (didn't leave work until 6.30!).
To give a bit of background, what I'm trying to write is a script which will:
1. Find all the domains in my organisation (get that with NET VIEW /DOMAIN).
2. List all hosts on each domain (get that with NET VIEW /DOMAIN:domainname).
3. List all shares on each of those hosts (NET VIEW /DOMAIN:domainname \\hostname).
4. Search through every share for a particular word in a set of file types.
1 & 2 are fully working now with cleaned-up outputs.
3 is what I'm working on.
4 Isn't really going to be used, it's just to practice my scripting ability.0 -
hi there
have u used the DSGET or DSQUERY commands?
regards0 -
Since you seem to know what you're doing (!), I hope you understood what I was doing in my BATch file and can adapt it accordingly!0
-
This discussion has been closed.
Confirm your email address to Create Threads and Reply

Categories
- All Categories
- 352K Banking & Borrowing
- 253.5K Reduce Debt & Boost Income
- 454.2K Spending & Discounts
- 245K Work, Benefits & Business
- 600.6K Mortgages, Homes & Bills
- 177.4K Life & Family
- 258.8K Travel & Transport
- 1.5M Hobbies & Leisure
- 16.2K Discuss & Feedback
- 37.6K Read-Only Boards