user3026965
user3026965

Reputation: 713

Metadata export error when running on large directory structures

This script exports the basic file metadata in PowerShell to a .csv.

PS K:\> Get-childitem -recurse -file | select-object length,lastwritetime,fullname | export-csv filelist.csv -notypeinformation

It works great on simple directory structures of 10-20K files, but when I run it on 500K+ files of complex, multi-level directory structures it freezes or gives me error:

At line:1 char:1
+ Get-childitem -recurse -file | select-object length,lastwritetime,ful ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CallDepthOverflow

Is this a problem with the -recurse or else? Using PowerShell 5 1 (Major Minor).

Upvotes: 1

Views: 172

Answers (1)

ShanayL
ShanayL

Reputation: 1247

Test to see how long the filepaths are.

If the filepaths are more than 248 characters... That may be why you are getting the error.

To check to see if any come back with more than 248 characters you can do

Get-childitem "filepath" -recurse  | % {
    $filepath = $_.FullName
    $charactercount = ($filepath | Measure-Object -Character).Characters
    If ($charactercount -gt 248){write-host $filepath}
}

Upvotes: 2

Related Questions