Quickly Find Shares on a DC

The first I knew there was a problem was when the support calls started coming in – “Our Network drive is missing!”. It couldn’t possibly have been what I was doing, creating a DFS namespace Root with the same name as one of our network shares. It has been tested as ok, and accepted through change management so why were people calling? In the post mortem, it became clear – the testing had been against DC, but in production a number of our DCs were file servers too and the DFS Root share had “stolen” the existing share.

Ouch.

Time to see what shares were on DCs/File Servers and pick a unique share name

The script itself is simple, indeed its only a few lines:

$serverlist = Get-QADComputer -searchroot ‘health.local/Domain Controllers’ -SearchScope OneLevel
foreach ($server in $ServerList) {
$Share = gwmi -computername $($server.Name) -class Win32_Share
Write-Output $server.name
$Share | ft name, path -auto
}

Using the Quest AD Management cmdlets, we get a list of servers in AD that are in the Domain Controllers OU (All DCs should be in this group, and if they are you should look at moving them back there). A WMI query enumerates the shares names and outputs the Server name and share details to output.

The second-last line can be altered like so, if you are looking for a particular share name

$Share | Where {$_.name -eq “myshare” } | ft name, path -auto

I won’t get caught making DFS Namespaces with the same name as shares again 🙂

Advertisements