Solved

file share and directory report

Posted on 2014-04-08
10
426 Views
Last Modified: 2014-05-28
is there any easy way in powershell to produce a report around a file servers structure?

i.e. essentially I want it to report all shares and the root level directories into one report. I dont want the report to go any deeper that the top level root folders per share i.e.\\server\share\folder1 \\server\share\folder2? I would be running the script with domain admin permissions so it should have permissions to enumerate everything. Ideally written to CSV would be excellent?
0
Comment
Question by:pma111
10 Comments
 
LVL 10

Expert Comment

by:Scott Thomson
ID: 39985313
What sort of data are you hoping to extract from this report my friend??

You want just the top folder name and you want to know
- How many folders and files are in the subdirectories?
- What size the top level folder and all subdirectories equal?

So I guess what I am asking is
Lets say you have 10 folders in the top directory
Finance
Administration
IT
Management
ETC

Do you want a detailed report of files and folders and size etc under each of the main directories so you can show a manager how much space finance is wasting (it's always finance ) ^_^ or something similar..?
0
 
LVL 3

Author Comment

by:pma111
ID: 39985360
Numbers would be great. I am not to bothered about size of each directory but theres no harm including that directory and it could be useful.

I.e. say for example my server has 5 shares, and in those 10 root (top) level directories, I'd expect the report to list 50 rows of data. However, it would be great to see how many sub dirs are in each root level directory, but this information isnt essential. So just UNC paths would be sufficient in the end report.

Ideally the end report would be something along the lines of

\\server1\share1\dir1
\\server1\share1\dir2
\\server1\share2\dir1
\\server2\share1\dir1

etc, ideally written to CSV.
0
 
LVL 10

Expert Comment

by:Scott Thomson
ID: 39985372
So just to confirm

UNC paths of each of the top level directories?
All thrown into a CSV?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Author Comment

by:pma111
ID: 39985419
Yes please
0
 
LVL 3

Author Comment

by:pma111
ID: 39993779
Is this not doable?
0
 
LVL 43

Accepted Solution

by:
Davis McCarn earned 167 total points
ID: 40090935
I'm an old fashioned kind of guy and use the CMD prompt regularly so chew on this one:\

net view \\%computername% >> g:\%computername%-shares.txt

If you substitute g: with a path to a share and push it to however many servers or PC's you want, you'll wind up with a listing of all of the shares.  If you want them all in one file, create a blank shares.txt file and use this:

net view \\%computername% > \\<servername>\<sharename>\shares.txt
0
 
LVL 39

Assisted Solution

by:footech
footech earned 167 total points
ID: 40090975
Yes, it's possible.
An easy way?  That's a matter of opinion, and all depends on what information you need/want, how you want it formatted, and in what scenarios you want it to work.

With that said, I generally try to discourage people from asking for complete scripts here that involve anything more than few lines.  It's much better to ask questions on particular points that you get stuck on or need explanation.  Contribute whatever code you have, whether written by yourself or found elsewhere, and show where you're stuck.  The MS Technet Script Repository is a great place to start.  You can search for results by type of script.
Technet Script Repository

Something like the following would pretty much give the info you want for the local machine.
Get-WmiObject win32_share  -filter "type = 0" | % { Get-ChildItem $_.path | ? {$_.PsisContainer} } | select fullname

Open in new window

But as I mentioned, formatting the data (e.g. to show UNC paths), working against remote computers, and choosing other data to display all adds to the code.
0
 
LVL 24

Assisted Solution

by:Lionel MM
Lionel MM earned 166 total points
ID: 40091900
OK I just tested a batch file--works but is not all that clean--maybe someone can helps to remove extra text from files. Put this in a batch file--let's call it ee1.Bat
@Echo Off
Set Server=YourServerName
net view \\%Server% >C:\Utils\%Server%.Txt
for /F "skip=1 tokens=1 delims=," %%i in (C:\Utils\%Server%.Txt) do dir /ad \\%Server%\%%i

Now save it and then from a command ling type ee1 >results.txt
The net view \\%Server% >C:\Utils\%Server%.Txt will have more info than we need, with heading and the like so maybe someone can help to clean up this file.
The "for /F "skip=1 tokens=1 delims=,"" will then go through that file do a dir of just the top level folders (/ad and no /s) in that share. Using the @Echo Off provides the cleanest output but with some tweaking the results.txt can be better.

Let me know if this is somewhat what you want--thanks.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Issue: One Windows 2008 R2 64bit server on the network unable to connect to a buffalo Device (Linkstation) with firmware version 1.56. There are a total of four servers on the network this being one of them. Troubleshooting Steps: Connect via h…
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question