Tip: You can use the parameter ReadCount of Get-Content cmdlet to increase the number of lines sent to pipeline.
The default value is 1 (each line is sent to pipeline to the next command at a time).
The value 0 sends all of the content at one time (when working with large items, it can speed up the time it takes to process).
You could specify the value you want depending on your situation.
As a quick demo, I have a file “paths.txt” (64 MB) which contains all the files (FullName) of one computer.
1 2 3 4 5 6 7 8 9 10 |
# ReadCount = 1 (By default, one line is sent to pipeline at a time) Get-Content -Path .\files.txt -ReadCount 1 | ForEach-Object { Split-Path -Path $_ -Leaf } | Out-File -FilePath 'C:\Demo\FileReadCount1.txt' # ReadCount = 0 (All lines are sent to pipeline) Get-Content -Path .\files.txt -ReadCount 0 | ForEach-Object { Split-Path -Path $_ -Leaf } | Out-File -FilePath 'C:\Demo\FileReadCount0.txt' |
Files generated are the same but we gained 24 seconds by using -ReadCount 0.