Batch file wanted to list all shares on network by servername/share

Posted on 2008-11-05
Last Modified: 2013-11-05
I have a network with several hundred Windows 2003 servers.  I need to get a list of all of the network shares by servername.  I am hoping this can be done by using a batch file.

Preferrably, I would like to have a text file that lists each server name.  The batch file would take each server name, check the server, and then append an output text file with the shares for that server.  It would then continue down the server list until it reached the end.  The text file would look something like this:


The exact format doesn't matter as much as just being able to collect the information in a text file.
Question by:Config_Dot_Sys
    LVL 1

    Accepted Solution

    From WinDrivers forum...
    I will be making use of this myself.

    net view /domain:Your_Domain>>machinelist.txt
    for /f %%i in (machinelist.txt) do net view %%i>>shares.txt
    del machinelist.txt
    LVL 1

    Author Closing Comment

    Exactly what I needed, Dabecs.  Thanks!
    LVL 18

    Expert Comment

    Here is a script I recently created myself which would do what you need:
    All you need is a file(input file) list all ther servers which can be easily obtained from many different sources, even with ADCU's export list feature. The other file is the output file which will automatically be created with info as you needed: ServerName, ShareName & Path. Each servername will be separated by a line. I inlcuded the path thinking that it may be useful for you but you can take it out as you wish.
    Hope this help.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile("C:\temp\ServerList-Out.txt")
    Set objFileIn = objFSO.OpenTextFile("C:\temp\ServerList-In.txt", 1)
    Const ForAppending = 8
    Set objFileOut = objFSO.OpenTextFile("C:\temp\ServerList-Out.txt", ForAppending)
    Do Until objFileIn.AtEndOfStream
     	strLine = objFileIn.ReadLine
    	On Error Resume Next
    	strComputer = strLine
    	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    	Set colItems = objWMIService.ExecQuery("Select * from Win32_Share",,48)
    	objFileOut.WriteLine "ServerName: " & strComputer
    	For Each objItem in colItems
        		objFileOut.WriteLine "ShareName: " & objItem.Name
        		objFileOut.WriteLine "Path: " & objItem.Path

    Open in new window


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    A common practice in small networks is making file sharing easy which works extremely well when intra-network security is not an issue. In essence, everyone, that is "Everyone", is given access to all of the shared files - often the entire C: drive …
    This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now