Network Share Inventory

*This is my first post and I want to apologize in advance is case my post does comply to any of your rules.

So I have never really scripted or written a code for any solution out there so my question will be very basic and im not looking for a “prepared meal” but instead I want some directions so that I can come up with my own solution. I was given the task to generate a report from a Shared Drive (xxTBs) that is essentially used as a common repository for various department. My goal is to be able to use PowerShell (but Im open for suggestions as to whether or not this is the best idea) to gather: (File Name/Extension/Location-FolderPath/Size - MB and GB/LastModifiedDate/Created Date/Accessed/Type of the file-extension). It needs to go through all folders and subfolders in the shared location and if some for reason an particular folder isnt accessible, skip and keep scanning…if Im not wrong it has to ignore the 256 character name too.

From what I have read, I should be using the Get-ChildItem…(again open to suggestions)

So I started this Get-ChildItem -Path networkshare$ -Recurse | Select-Object Name,Type,FolderPath,Size

Am I in the right direction here?

Hello Med70, welcome to the club.
You are on the right track, although if it is a large drive and on the network, it is going to take a while and you may not get all of the options you are after.
I’d start with a small number of files and against the local disk. This might be a good starting point:
https://gallery.technet.microsoft.com/scriptcenter/Disk-Usage-Analyser-e4b05c1d
Use out-gridview instead of format-table while playing with it.

Here’s the simple route:

Permissions and ‘PathTooLong’ are common culprits for causing exceptions otherwise you’ll just get the output of what is found; so if those aren’t important to capture (or any other errors for that matter), you could use -ErrorAction SilentlyContinue:

Get-ChildItem -Path networkShare$ -Recurse -ErrorAction SilentlyContinue | Select-Object Name, Type, ...

At the end of the script you may want to do something like

$Error.count

That’ll give you an indication of the number of errors that occured. If you’re feeling REALLY masochistic you could also do:

$error |add-content MyErrors.txt

That’ll put the errors into one text file.

$Error.clear()

That’ll clear the errors out of memory, giving you a count of 0

not sure how deep down the rabbit hole you have to go, but to find all of the shares on a windows server you can start here:

Get-WmiObject -ComputerName $computer -Class Win32_Share

Then you can loop through those with get-childitem, and use recursive with levels to see how deep you need to go.

beware, i’ve had some extremely large numbers of files in some paths i’ve had to pull acl reports for, and have seen 600k plus entries for some stuff, so think about that before just doing a blanket recursive for get-childitem.