Skip to content

How to List Network Shares in a Batch Script

Learn how to audit and list network shares in Windows using NET VIEW, NET SHARE, and the powerful WMIC command in batch scripts for local and remote systems.

A network share is a folder on a computer that has been made available for other users on the network to access. For system administrators, auditing these shares is a crucial security and maintenance task. You might need to generate a report of all shares on a server, check if a specific folder is shared, or simply get a quick overview of what resources a machine is offering to the network.

This guide will teach you how to list network shares using the two primary built-in Windows commands for this task: the classic NET VIEW and NET SHARE commands, and the modern and more powerful WMIC command.

The Core Commands: NET VIEW, NET SHARE, and WMIC

Windows provides several built-in tools for this task, each suited for a slightly different purpose.

  • NET VIEW \\ComputerName: This is the classic command to list the shares on a remote computer. It shows you what another machine is sharing.
  • NET SHARE: This command, when run with no arguments, lists all the shares created on the local computer.
  • WMIC SHARE: This is the modern and most powerful method. It can list local shares with far more detail and in a script-friendly format.

Listing Shares on a Remote Computer (NET VIEW)

The NET VIEW command is the simplest way to see what shares are available on another computer on your network.

Syntax:NET VIEW \\ComputerName

@ECHO OFF
SET "TargetServer=FILESERVER-01"

ECHO --- Listing shares on %TargetServer% ---
ECHO.
NET VIEW \\%TargetServer%

The command produces a clean, table-formatted list of share names and their comments as output:

Shared resources at \\FILESERVER-01

Share name   Type   Used as  Comment
-------------------------------------------------
Data         Disk            Company Shared Data
Profiles     Disk            User Profiles
Scans        Disk            Incoming Scans from MFD
The command completed successfully.

Listing Shares on the Local Computer (NET SHARE)

To see what shares are configured on the machine you are currently on, you use NET SHARE.

Command: NET SHARE

This command provides more detail than NET VIEW, including the local path that is being shared. It also lists the hidden administrative shares (like C$ and ADMIN$).

Share name   Resource                        Remark
-------------------------------------------------------------------------------
C$           C:\                             Default share
IPC$                                         Remote IPC
ADMIN$       C:\WINDOWS                      Remote Admin
Data         C:\Shared\Data                  Company Shared Data
...

For any automation task, WMIC is the superior tool. It provides the most detail and its output is structured and easy for a script to parse.

Command: WMIC SHARE GET Name,Path,Caption

This produces a clean, space-padded table that is ideal for scripting, as Output:

Caption                Name   Path
OK                     ADMIN$ C:\WINDOWS
OK                     C$     C:\
Company Shared Data    Data   C:\Shared\Data
Remote IPC             IPC$
OK                     Profiles C:\Users\Profiles
OK                     Scans  C:\Scans

Parsing the Output to Process Each Share

The real power of WMIC comes from the ability to use its output in a FOR loop. This allows you to perform an action on each share found.

This script iterates through each non-hidden share on the local machine and prints its details.

@ECHO OFF
ECHO --- Auditing Local Network Shares ---
ECHO.

REM 'skip=1' ignores the header line.
REM 'tokens=1,2,*' separates the columns.
FOR /F "skip=1 tokens=1,2,*" %%A IN ('WMIC SHARE GET Caption^,Name^,Path') DO (
    
    REM --- Use a trick to see if the share name contains a '$' ---
    ECHO %%B | FIND "$" > NUL
    IF ERRORLEVEL 1 (
        ECHO Share Name: "%%B"
        ECHO Local Path: "%%C"
        ECHO Description: "%%A"
        ECHO.
    )
)

Common Pitfalls and How to Solve Them

  • Permissions: While listing shares on the local machine is usually fine, listing shares on a remote computer (NET VIEW) or getting detailed WMIC info can fail with an "Access is denied" error.

    • Solution: For remote auditing, you must be running the script as a user with at least local administrator rights on the target machine. Ensure firewalls are configured to allow "File and Printer Sharing."
  • Hidden Administrative Shares: By default, the NET SHARE and WMIC SHARE commands will list the hidden administrative shares (ending with a $).

    • Solution: As shown in the practical example, you can pipe the output to FINDSTR /V "\$" to filter out lines containing a dollar sign, or use the FIND trick as shown above.

Practical Example: An Audit Script for Server Shares

This script uses the robust WMIC method to generate a CSV report of all non-hidden shares on a remote server. This is perfect for security and configuration auditing.

@ECHO OFF
SETLOCAL
SET "TargetServer=FILESERVER-01"
SET "ReportFile=Share_Audit_%TargetServer%.csv"

ECHO --- Share Audit Script ---
ECHO Auditing server: %TargetServer%
ECHO Report will be saved to: %ReportFile%
ECHO.

REM --- Create the CSV Header ---
ECHO "Share Name","Local Path","Description" > "%ReportFile%"

REM --- The WMIC Query and Loop ---
FOR /F "skip=1 tokens=1,2,*" %%A IN ('WMIC /NODE:"%TargetServer%" SHARE GET Caption^,Name^,Path') DO (
    REM Check if the share name is hidden (contains '$')
    ECHO %%B | FIND "$" > NUL
    
    REM If it's NOT a hidden share, append it to the CSV.
    IF ERRORLEVEL 1 (
        ECHO "%%B","%%C","%%A" >> "%ReportFile%"
    )
)

ECHO [SUCCESS] Audit report created.
ENDLOCAL
  • /NODE:"%TargetServer%": This is the WMIC syntax for targeting a remote computer.

Conclusion

Windows provides several powerful, built-in tools for listing network shares.

  • NET VIEW \\Server is the quickest way to see the shares on a remote machine.
  • NET SHARE is the standard way to list shares on the local machine.
  • WMIC SHARE is the most powerful and recommended method for any scripting or automation. It provides detailed, structured output that is easy to parse.

By using WMIC with a FOR /F loop, you can easily create robust scripts to audit, document, and manage the shared resources on your network.

Navigation