How do I get a list of all shared folders from all servers?


This script will, unaltered, find all servers in Active Directory and probe each for its shared folders (using WMI).  It is set to automatically exclude the default shares lik SYSVOL, system drive shares (C$, D$ etc), printer shares and others.



The result should list each server name, with a list of shares names and local drive locations of those shares:



7 Comments How do I get a list of all shared folders from all servers?

  1. Bradford

    I changed ($ -notmatch “.\$”) to ($ -notmatch “^.\$”) because it was matching on all hidden shares instead of just the admin drive shares.
    Also, there’s another print share: ($ -ne “prnproc$”)

    Final statement:
    if (($ -ne “print$”) -and ($ -ne “prnproc$”) -and ($share.path -notlike “*LocalsplOnly*”) -and ($ -notmatch “^.\$”) -and ($ -ne “ipc$”) -and ($ -ne “sysvol”) -and ($ -ne “netlogon”)-and ($ -ne “admin$”))

      1. John Gilmore

        That is great. I have been working on getting this to export to CSV or HTML I don’t think I know what I need to know yet.

        Can anyone help?

        1. Kamal

          Rather than using write-host, you should build a comma separated string like this:
          $out = $ + "," + $ + "," + $share.path

          And then append that to a file with:
          $out >> c:\temp\output.csv

    1. Kamal

      Yes – you definitely can, although it’s a little more complex.
      After you run the gwmi win32_share command, it returns the Path to the share (as $share.path in the foreach loop). You can use that drive letter in a gwmi win32_logicaldisk query to get the total/used/free space, similar to how I used it here:


Leave a Reply

Your email address will not be published. Required fields are marked *