0

The local network contains a few file server that each has multiple shares.

I would like to get a complete recursive directory listing for a given host. Unfortunately dir /S /B \\servername does not work.

I would have to call dir /S /B \\servername\share for each share separately.

Is there a more easy way?

Also the process should not stop or abort if directory has no access rights.

3 Answers3

0

This PowerShell one-liner will list all the shares of the specified computer, and for each share will list all its files:

foreach($Share in Get-WmiObject Win32_Share -ComputerName 'COMPUTER') {Get-ChildItem "\\$($Share.__SERVER)\$($Share.Name)"}

You may all invoke it from a Command Prompt (cmd) or batch (.bat) as:

powershell "foreach($Share in Get-WmiObject Win32_Share -ComputerName 'COMPUTER') {Get-ChildItem "\\$($Share.__SERVER)\$($Share.Name)"}" >\path\outfile.txt

EDIT

For querying a non-Windows server, the problem is that the above requires an RPC server which is not available.

You might try using WMIC instead. Enter in the PowerShell command prompt the following two lines for one such Linux server:

$allshares = (net view \\SERVER) | % { if($_.IndexOf(' Disk ') -gt 0){ $_.Split('  ')[0] }}
foreach ($Share in $allshares) {Get-ChildItem "\\SERVER\\$Share"}
harrymc
  • 498,455
-1

through explorer open the folder containing the shares. Hold shift and right click. Choose open powershell or cmd here and type: dir > textfile.txt

-1

Create a text file called C:\Folders.txt

Run this in Powershell :

Get-ChildItem "\\192.168.2.4\Home" -Recurse -Name -Directory | Out-File "C:\Folders.txt"
JW0914
  • 9,096