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.

  • You can start by looking at this question. – DOBRESCU_Mihai Nov 13 at 12:49
  • thank you. that link helps. however it seems it is not feasable to do without net view and result parsing – vlad_tepesch Nov 14 at 9:24

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


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"}
  • 1
    that does not work. this gives error that there is no RPC server that can execute wmi-requests (the server are either simple NAS or some other linux based file servers). it seems that there is no way around net view server and parsing the result with some script language – vlad_tepesch Nov 14 at 9:22
  • It worked for me. Perhaps the difference is that a firewall is blocking your RPC. The ports are 135 and dynamic ports above 1024. Perhaps this link might be useful for troubleshooting. – harrymc Nov 14 at 9:29
  • since some are not a windows machine they do not have a RPC service that answe WMI-Reqests – vlad_tepesch Nov 14 at 10:01
  • I added an alternative syntax that uses WMIC instead. Try to see if it works better. – harrymc Nov 14 at 10:47
  • I hoped that there would a simple command. I knew the net view approach but it has a lot of gotchas: net view is localized and its output depends on the language settings. in German Windows eg. Disk is translated Plattte. My implemented approach is looking for the delimiter line, go two up, look at which character the second column starts and how long the line is and then checking in each following line if the the line length matches and the last character of the first column is a space because splitting at Space is also not possible (white spaces in share names) – vlad_tepesch Nov 14 at 13:28

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

  • this would create a file on the remote server that may not even be possible. but beside from this, this is exactly that i suggested in the "I would have to call...." sentence – vlad_tepesch Nov 13 at 13:34

Create a text file called C:\Folders.txt

Run this in Powershell :

Get-ChildItem "\\\Home" -Recurse -Name -Directory | Out-File "C:\Folders.txt"
  • but this already accessed the share Home. my question is about only passing a host name. your answer is identical to my dir /AD /S /B \\somehost\Home (and i do not even want the /AD) – vlad_tepesch Nov 14 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.