As Abraham Zinala mentions, you might want to take advantage of Get-Content -ReadCount
, to read the file in chunks of 1000 lines at a time, then output to CSV and continue with the next chunk:
$outputCounter = 1
Get-Content path\to\huge\file.txt -ReadCount 1000 |ForEach-Object {
# Iterate over file paths in chunk, fetch ACL information, then write all 1000 records to a new CSV file
$_ |ForEach-Object {
Get-Item -LiteralPath $_ -PipelineVariable item |Get-ACL |Select @{Name='Path';Expression={$item.FullName}},Owner -ExpandProperty Access
} |Export-Csv ".\path\to\output_${outputCounter}.csv" -NoTypeInformation
# Increment output file counter
$outputCounter++
}