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

4 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

Leave a Reply

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