Jimcesseg
Jimcesseg

Reputation: 15

Query a bigger file server for files and folders with get-childitem

I have a big file server more than 15 TB of files and folders, and I need to get all full names whith get-childitem, I am doing that:

$FSData = Get-ChildItem -Path C:\FS01 -Filter * -Recurse -Force

But the server consume of memory is for 16GB, I wonder if there is any way to query and save to CSV without wait for the cmdlet finish memory dump.

Upvotes: 0

Views: 433

Answers (1)

Daniel
Daniel

Reputation: 5114

I would suggest using StreamWriter which will open the file only once and buffer input. It managed to log all the filenames from my C:\ drive (925,232 files) in about 1 minute 15 seconds

$sw = [System.IO.StreamWriter]::new('c:\temp\filelist.log');
$options = [System.IO.EnumerationOptions]::new()
$options.RecurseSubdirectories = $true
$options.AttributesToSkip = 0
[System.IO.Directory]::EnumerateFileSystemEntries('C:\FS01', '*', $options).ForEach( { $sw.WriteLine($_) }); 
$sw.Dispose()

Note EnumerateFileSystemEntries() returns both files and directories. If you only want files use [System.IO.Directory]::EnumerateFiles('C:\FS01', '*', $options)

Upvotes: 0

Related Questions