Quite a few businesses have server networks that were grown over time with servers being added to meet some demand or another – a’ la carte – rather than a designed network in which an architect planned the distribution of every platform and it’s associated servers. The organic distribution of systems often results in nobody knowing what’s out there in total. Sure, the admins know what’s on the systems that they take care of but who has the big picture?

Recently, I was asked how many windows file shares were on a network that I help support. As it turns out, the answer was that nobody knew. None of our existing tools had a mechanism that would help us investigate quickly and easily. I’m glad I paid attention in PowerShell class.

The code below will connect to a domain controller and locate all of the Windows Server computers. Then, it will scan each one for file shares using WMI (excluding admin and IPC shares) and report the results in a csv.

Import-Module ActiveDirectory

$servers = Get-ADComputer -Properties * -Filter {(OperatingSystem -like "*Windows Server*")}|Select DNSHostName -ExpandProperty DNSHostName

$filter = "Type = 0 And Description != 'Default Share' And " +
"Name != 'ADMIN$' And Name != 'IPC$'"

$servers |
ForEach-Object { Get-WmiObject -Computer $_ -Class Win32_Share -Filter $filter } |Select-Object @{n='Computer';e={$_.__SERVER}}, Name, Path, Description |
Export-Csv -Path $env:userprofile\documents\server_shares.csv -NoTypeInformation
Advertisements