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

green

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:

shares

green

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

  1. Bradford

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

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

    Reply
      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?

        Reply
        1. Kamal

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

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

          Reply
    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:

      https://hkeylocalmachine.com/?p=745

      Reply

Leave a Reply to Kamal Cancel reply

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