- This topic has 4 replies, 5 voices, and was last updated 3 months, 1 week ago by
October 18, 2019 at 2:53 am #183648ParticipantTopics: 1Replies: 0Points: 17Rank: Member
*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?
October 18, 2019 at 7:02 am #183741ParticipantTopics: 3Replies: 28Points: 31Rank: Member
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:
Use out-gridview instead of format-table while playing with it.
October 18, 2019 at 7:27 am #183747ParticipantTopics: 10Replies: 118Points: 508Rank: Major Contributor
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
Get-ChildItem -Path networkShare$ -Recurse -ErrorAction SilentlyContinue | Select-Object Name, Type, ...
October 21, 2019 at 3:22 pm #184173ParticipantTopics: 1Replies: 63Points: 355Rank: Contributor
At the end of the script you may want to do something like
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.
That'll clear the errors out of memory, giving you a count of 0
October 21, 2019 at 7:17 pm #184227ParticipantTopics: 23Replies: 163Points: 474Rank: Contributor
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.
- The topic ‘Network Share Inventory’ is closed to new replies.