Network Share Inventory

Welcome Forums General PowerShell Q&A Network Share Inventory

Viewing 4 reply threads
  • Author
    Posts
    • #183648
      Participant
      Topics: 1
      Replies: 0
      Points: 17
      Rank: 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?

    • #183741
      AK
      Participant
      Topics: 3
      Replies: 28
      Points: 31
      Rank: 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:
      https://gallery.technet.microsoft.com/scriptcenter/Disk-Usage-Analyser-e4b05c1d
      Use out-gridview instead of format-table while playing with it.

    • #183747
      Participant
      Topics: 10
      Replies: 106
      Points: 388
      Helping Hand
      Rank: 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 -ErrorAction SilentlyContinue:

      Get-ChildItem -Path networkShare$ -Recurse -ErrorAction SilentlyContinue | Select-Object Name, Type, ...
    • #184173
      Participant
      Topics: 1
      Replies: 63
      Points: 355
      Helping Hand
      Rank: Contributor

      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

    • #184227
      Participant
      Topics: 23
      Replies: 159
      Points: 425
      Helping Hand
      Rank: 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.

       

Viewing 4 reply threads
  • You must be logged in to reply to this topic.