Solved

file share and directory report

Posted on 2014-04-08
10
422 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
Comment Utility
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
Comment Utility
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
Comment Utility
So just to confirm

UNC paths of each of the top level directories?
All thrown into a CSV?
0
 
LVL 3

Author Comment

by:pma111
Comment Utility
Yes please
0
Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

 
LVL 3

Author Comment

by:pma111
Comment Utility
Is this not doable?
0
 
LVL 42

Accepted Solution

by:
Davis McCarn earned 167 total points
Comment Utility
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
Comment Utility
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:lionelmm
lionelmm earned 166 total points
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Synchronize a new Active Directory domain with an existing Office 365 tenant
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now