Solved

file share and directory report

Posted on 2014-04-08
10
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
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 40

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 25

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

Webinar: MariaDB® Server 10.2: The Complete Guide

Join Percona’s Chief Evangelist, Colin Charles as he presents MariaDB Server 10.2: The Complete Guide on Tuesday, June 27, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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